ES6+ (Modern JavaScript) Tutorial
Modern JavaScript features from ES2015 onward: modules, classes, destructuring, async and more.
- Topics
- 23
- Full lessons
- 23
- Est. hours
- ~4
- Interview Qs
- 25
Overview
ECMAScript is the specification that defines the JavaScript language. ES6 (officially ES2015) was a major update, and new editions have been published every year since.
“Modern JavaScript” covers ES2015 and the features added afterwards, such as async/await (ES2017), optional chaining and nullish coalescing (ES2020).
What you will learn
- Write concise code with arrow functions, destructuring and spread
- Organise code into ES modules
- Use classes, symbols, iterators and generators
- Handle missing data safely with ?. and ??
Learning path
The recommended sequence, from beginner to advanced. Each stage builds on the one before.
- 1Foundations · 5 topics · BeginnerIntroduction to ECMAScript · let and const · Arrow Functions · Template Literals · Default Parameters
- 2Working with Data · 4 topics · Beginner → IntermediateDestructuring · Spread Operator · Rest Parameters · Enhanced Object Literals
- 3Structure · 7 topics · IntermediateClasses · Modules · Promises · Symbols · Iterators · Generators · Map and Set
- 4ES2020 and Later · 5 topics · AdvancedOptional Chaining · Nullish Coalescing · Dynamic Imports · Modern Array Methods · Async and Await
- 5Practice · 2 topics · AdvancedES6 vs Older JavaScript · Practical Examples
Complete topic list
23 topicsFoundations
5 topics- Introduction to ECMAScriptBeginner5m
- let and constBeginner5m
- Arrow FunctionsBeginner5m
- Template LiteralsBeginner5m
- Default ParametersBeginner5m
Working with Data
4 topics- DestructuringBeginner5m
- Spread OperatorIntermediate5m
- Rest ParametersIntermediate5m
- Enhanced Object LiteralsIntermediate5m
Structure
7 topics- ClassesIntermediate5m
- ModulesIntermediate6m
- PromisesIntermediate5m
- SymbolsIntermediate5m
- IteratorsIntermediate5m
- GeneratorsIntermediate5m
- Map and SetIntermediate5m
ES2020 and Later
5 topics- Optional ChainingAdvanced5m
- Nullish CoalescingAdvanced5m
- Dynamic ImportsAdvanced5m
- Modern Array MethodsAdvanced5m
- Async and AwaitAdvanced5m
Practice
2 topics- ES6 vs Older JavaScriptAdvanced6m
- Practical ExamplesAdvanced6m
Code example
A taste of the track, from Introduction to ECMAScript.
const user = { name: 'Asha', city: 'Pune' };
const { name, city } = user; // destructuring (ES2015)
const greet = n => `Hello, ${n} from ${city}!`; // arrow + template literal (ES2015)
console.log(greet(name));
const scores = [70, 85, 90];
console.log(Math.max(...scores)); // spread (ES2015)
console.log(user.address?.pin ?? 'no pin'); // ?. and ?? (ES2020)
Hello, Asha from Pune! 90 no pin
Practice exercises
Rewrite this ES5 code in modern syntax: var a = [1, 2]; var b = a.concat([3]); var msg = "Total items: " + b.length; console.log(msg);
Fix this so it logs 1, 2, 3 instead of 4, 4, 4: for (var n = 1; n <= 3; n++) setTimeout(() => console.log(n));
Convert to arrows: function double(n) { return n * 2; } and function toPair(k, v) { return { key: k, value: v }; }
Write a function card(user) that returns a multi-line string: line 1 the name in uppercase, line 2 “Age: X”, line 3 “Adult” or “Minor”.
Write formatPrice(amount, { currency = "₹", decimals = 2 } = {}) that returns e.g. "₹99.50".
Given const point = [3, 4], swap the values into x and y using destructuring, then swap x and y with each other.
Show all 23 exercises
Given const state = { user: { name: "Asha", city: "Pune" }, theme: "light" }, create a new state with city "Mumbai" without changing the original.
Write max(...nums) that returns the largest number, and use object rest to remove "id" from { id: 1, title: "Note", body: "Hi" }.
Write a function handleChange(form, inputName, value) that returns a new form object with that field updated.
Create a class Counter with a private #count, methods increment() and reset(), a getter value, and a static method from(n) that returns a counter starting at n.
Create a module greetings.js with a named export hello(name) and a default export goodbye(name). Then write the import line for both in app.js.
Write timeout(promise, ms) that rejects with "Timed out" if the promise takes longer than ms.
Create a Money class whose instances print as "₹500" in template literals and behave as 500 in arithmetic.
Make an object countdown = { from: 3 } iterable so that [...countdown] gives [3, 2, 1].
Write a generator range(start, end, step = 1) and use it to print the even numbers from 0 to 10.
Given words = ["a", "b", "a", "c", "b", "a"], build a Map of word counts and print the most frequent word.
Return the first tag of a post in upper case, or "UNTAGGED" if post, post.tags or the first tag is missing.
Write getLimit(query) that returns query.limit if provided (even 0), otherwise 25. Then make it safe when query itself is undefined.
Write a function openEditor() that dynamically imports "./editor.js", calls its default export with "#editor", and shows an alert if loading fails.
Given orders = [{ id: 1, status: "paid", total: 500 }, { id: 2, status: "pending", total: 200 }, { id: 3, status: "paid", total: 300 }], group them by status and get the paid orders sorted by total (ascending) without mutating.
Given ids = [1, 2, 3] and getUser = id => wait(100, { id }), fetch all users in parallel and log how many were loaded.
Modernise: var self = this; var total = 0; items.forEach(function (item) { total = total + item.qty * item.price; }); console.log("Total: " + total);
Add a remove(id, qty = 1) method to Cart that lowers the quantity and deletes the line when it reaches 0.
Common interview questions
- What is ECMAScript and how does it relate to JavaScript?
- How do arrow functions differ from regular functions?
- Spread vs rest — what is the difference?
- Why were let and const added?
- What are template literals?
- How do default parameters work?
- What is destructuring?
- What are enhanced object literals?
- What are ES modules and how do named and default exports differ?
- What are Map and Set, and when are they better than objects and arrays?
- What is a Symbol?
- What does optional chaining do?
- ?? vs || — what is the difference?
- What are ES6 classes and what do they not change?
- How do iterators and the for…of loop work?
- What do async/await add on top of promises?
- How do you make an object immutable?
- What are dynamic imports and why use them?
- Name some modern array methods and their benefits.
- What are generators good for in practice?
- Which ES2015+ features need a polyfill rather than transpilation?
- What new array methods avoid mutating the original?
- Static import vs dynamic import()?
- What are well-known symbols?
- What is the difference between Promise.then chains and async/await for error handling?