const name = 'John'; const greeting = `Hello, ${name}. Welcome!`;
const user = { name: 'Alice', age: 25 }; const { name, age } = user; console.log(name, age); // Alice 25
const arr = [1, 2, 3]; const extended = [...arr, 4, 5]; console.log(extended); // [1, 2, 3, 4, 5] function sum(...nums) { return nums.reduce((acc, num) => acc + num, 0); } console.log(sum(1, 2, 3)); // 6
const fetchData = () => new Promise(resolve => setTimeout(() => resolve('Data fetched'), 1000)); fetchData().then(console.log);
class Animal { constructor(name) { this.name = name; } speak() { console.log(`${this.name} makes a noise.`); } }