Today you will learn:
...)By the end, you will write cleaner and more efficient code.
Arrow functions are a shorter syntax for functions:
const greet = (name) => `Hello ${name}`;
console.log(greet("John")); // Hello John
Template literals allow embedding variables into strings:
const name = "Alice";
console.log(`Hi, my name is ${name}`);
The spread operator can expand arrays or objects:
const arr1 = [1, 2];
const arr2 = [3, 4];
const merged = [...arr1, ...arr2];
console.log(merged); // [1, 2, 3, 4]
const greet = (name) => `Hello ${name}`;
console.log(greet("John"));
Complete the following:
Example:
// Merge arrays
const arr1 = [1, 2, 3];
const arr2 = [4, 5];
const combined = [...arr1, ...arr2];
console.log(combined); // [1,2,3,4,5]
// Template literal function
const welcome = (name, age) => `Hello ${name}, you are ${age} years old`;
console.log(welcome("Alex", 18));