- Deep object destructuring You probably know you can destructure objects, but did you know you can destructure a destructured object?
const {
dog,
cat: { legs, eyes, breed },
} = pets;
- Destructuring an array You can also destructure an array by its index
const {0: first, 5: sixth} = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"];
console.log(first) // expected output: "Jan"
console.log(sixth) // expected output: "Jun"
- The comma operator (,) Evaluates each of its operands (from left to right) and returns the value of the last operand.
let x = 1;
x = (x++, x);
console.log(x); // expected output: 2
x = (2, 3);
console.log(x); // expected output: 3
This is used when you need multiple variables for for
loops
for (var i = 0, j = 9; i <= 9; i++, j--)
console.log('a[' + i + '][' + j + '] = ' + a[i][j]);
Top comments (0)