Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
June 27, 2022 02:30 pm GMT

3 Javascript features you probably didn't know

  1. Deep object destructuringYou probably know you can destructure objects, but did you know you can destructure a destructured object?
const {    dog,    cat: { legs, eyes, breed },  } = pets;
  1. Destructuring an arrayYou 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"
  1. Thecomma 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: 2x = (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]);

Original Link: https://dev.to/__victorchan/3-javascript-features-you-probably-didnt-know-2936

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To