An Interest In:
Web News this Week
- April 2, 2024
- April 1, 2024
- March 31, 2024
- March 30, 2024
- March 29, 2024
- March 28, 2024
- March 27, 2024
June 27, 2022 02:30 pm GMT
Original Link: https://dev.to/__victorchan/3-javascript-features-you-probably-didnt-know-2936
3 Javascript features you probably didn't know
- 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;
- 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"
- 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:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To