course content

Course Content

Introduction to React

ES6 DestructuringES6 Destructuring

The older method of accessing and assigning values from an array was indexing:

However, ES6 has introduced a new method called destructuring, which enables us to access and assign values from an array easily:

The above method is much neater and requires less code.

We can also skip the elements we don't want to capture, for example, we can skip airVehicle but add an extra comma:

Note

The const keyword is for defining constant terms, you can also use the let keyword in the Destructuring statement.

question-icon

Complete the following code:

function stringVariants (str) {
    return [str.toLowerCase (), str.toUpperCase ()];
}
_ _ _
[
_ _ _
,
_ _ _
] = stringVariants ("Hello World!");
console.log (lower, upper);
hello world! HELLO WORLD!

Click or drag`n`drop items and fill in the blanks

dots
upper
dots
const
dots
lower
down-icon

Section 1.

Chapter 6