ES6+ Features Deep Dive
45 min

ES6+ Features Deep Dive

JavaScript has evolved dramatically since ES6. In this lesson, we cover the essential features every modern developer must master.

Arrow Functions provide concise syntax and lexical this binding. Unlike regular functions, they don't create their own execution context.

Destructuring allows you to unpack values from arrays and properties from objects into distinct variables. This makes code cleaner and more readable.

Template Literals use backticks and allow embedded expressions, multi-line strings, and tagged templates for advanced string processing.

Spread & Rest Operators (...) work with arrays and objects. Spread expands elements; rest collects them into arrays.

Promises & Async/Await handle asynchronous operations. Promises represent eventual completion or failure. async/await provides syntactic sugar for cleaner async code.

Optional Chaining (?.) safely accesses nested properties without checking each level. Nullish Coalescing (??) provides defaults only for null/undefined.

Key Takeaways

  • Arrow functions and lexical this binding
  • Destructuring arrays and objects
  • Template literals and tagged templates
  • Spread/rest operators for arrays and objects
  • Promises, async/await, and error handling
  • Optional chaining and nullish coalescing

Code Example

// Destructuring + Spread
const user = { name: 'ATAULLAH', role: 'Developer', country: 'BD' };
const { name, ...rest } = user;

// Async/Await with error handling
async function fetchData(url: string) {
  try {
    const res = await fetch(url);
    if (!res.ok) throw new Error(`HTTP ${res.status}`);
    return await res.json();
  } catch (err) {
    console.error('Fetch failed:', err);
    return null;
  }
}

// Optional chaining + nullish coalescing
const city = user?.address?.city ?? 'Unknown';