Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
ES6 Destructuring | Getting Started: ES6
Introduction to React
course content

Course Content

Introduction to React

ES6 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

Everything was clear?

Section 1. Chapter 6
We're sorry to hear that something went wrong. What happened?
some-alt