1)Destructuring:
The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values from arrays, or properties from objects, into distinct variables.
let a, b, rest;
[a, b] = [10, 20];
console.log(a);
// Expected output: 10
console.log(b);
// Expected output: 20
[a, b, ...rest] = [10, 20, 30, 40, 50]
console.log(rest);
// Expected output: Array [30, 40, 50]
The const
keyword was introduced in ES6 (2015).
Variables defined with const
cannot be Redeclared.
Variables defined with const
cannot be Reassigned.
Variables defined with const
have Block Scope.
But you can NOT reassign the array:
Example
const cars = ["Saab", "Volvo", "BMW"];
cars = ["Toyota", "Volvo", "Audi"]; // ERROR
const car = {type:"Fiat", model:"500", color:"white"};
car = {type:"Volvo", model:"EX60", color:"red"}; // ERROR
Comments
Post a Comment