Explore destructuring, spread operator, template literals, and more modern JavaScript features.
Example demonstrating destructuring, spread operator, and template literals:
// Destructuring
const user = { name: "Bob", age: 30 };
const { name, age } = user;
console.log(name); // "Bob"
// Spread operator
const arr1 = [1, 2];
const arr2 = [...arr1, 3, 4];
console.log(arr2); // [1, 2, 3, 4]
// Template literals
const greeting = `Hello, my name is ${name} and I am ${age} years old.`;
console.log(greeting);
// Arrow function
const add = (a, b) => a + b;
console.log(add(2, 3)); // 5
This code demonstrates:
ES6 introduced several key enhancements to JavaScript:
${expression}
.this
keyword.const
for constants and let
as a replacement for var
.import
and export
.Q1: What does the spread operator ...
do?
Answer: B. Expands arrays or objects into individual elements
Q2: Which syntax is used for template literals in ES6?
Answer: C. ` `
Q3: How do arrow functions differ from traditional functions?
this
valueAnswer: D. All of the above
Q4: Which keyword is used to import modules in ES6?
Answer: B. import