Template Literals
Template literals use backtick delimiters and embed expressions with
${...}. They support multi-line strings without escape sequences.
Arrow Functions
Arrow functions provide concise syntax and inherit this from the
enclosing scope. Single-expression bodies return implicitly; object literals
require parentheses.
Destructuring
Destructuring extracts values from arrays or properties from objects into
distinct variables. Rest syntax collects remaining items; default values
handle absent properties.
Async / Await
async functions always return a Promise. await
suspends execution until the awaited Promise settles, allowing sequential-style
code over asynchronous operations.
const name = 'World';
const msg = `Hello, ${name}!`;
const multiLine = `
line one
line two
`;
const expr = `sum = ${2 + 3}`; // "sum = 5"
const double = x => x * 2;
const add = (a, b) => a + b;
// implicit object return requires parens
const pair = x => ({ value: x, label: String(x) });
const nums = [1, 2, 3];
const doubled = nums.map(x => x * 2); // [2, 4, 6]
// array destructuring
const [first, second, ...rest] = [10, 20, 30, 40];
// object destructuring with rename and default
const { x: px = 0, y: py = 0 } = { x: 5 };
// in function parameter
function greet({ name = 'stranger', age }) {
return `${name} is ${age}`;
}
async function fetchUser(id) {
const res = await fetch(`/api/users/${id}`);
if (!res.ok) throw new Error(res.statusText);
return res.json();
}
// calling
const user = await fetchUser(42);
console.log(user.name);