ES6 (ECMAScript 2015) was a major update to JavaScript that introduced modern syntax, block-scoped variables, native modules, promises, and new data structures. Below are 10 frequently asked interview questions covering the core features of ES6.
![]()
1. What is the difference between var, let, and const?
varis function-scoped (or global-scoped if declared outside a function), can be redeclared in the same scope, and is hoisted with an initial value ofundefined.letis block-scoped ({}), cannot be redeclared in the same scope, can be reassigned, and resides in the Temporal Dead Zone (TDZ) until initialized.constis also block-scoped and cannot be redeclared or reassigned. Note thatconstprevents rebinding the variable reference—if aconstholds an object or array, its internal properties or elements can still be mutated.
if (true) {
var a = 1;
let b = 2;
const c = 3;
}
console.log(a); // 1
// console.log(b); // ReferenceError: b is not defined
// console.log(c); // ReferenceError: c is not defined
2. What is the Temporal Dead Zone (TDZ)?
The Temporal Dead Zone is the period between entering a block scope where a let or const variable is declared and the line where it is actually initialized. Accessing the variable inside the TDZ throws a ReferenceError rather than returning undefined.
if (true) {
console.log(count); // ReferenceError: Cannot access 'count' before initialization
let count = 10;
}
3. How do arrow functions differ from traditional functions?
Arrow functions (=>) provide shorter syntax and differ from regular function declarations/expressions in several key ways:
- Lexical
this: Arrow functions do not bind their ownthis; they inheritthisfrom the surrounding lexical scope. - No
argumentsobject: They do not have their ownargumentsobject (use rest parameters...argsinstead). - Not constructors: You cannot call an arrow function with
new, and they do not have aprototypeproperty.
const timer = {
seconds: 0,
start() {
setInterval(() => {
this.seconds++; // `this` refers to `timer`
}, 1000);
}
};
4. What are template literals, and what problems do they solve?
Template literals use backticks (```) instead of single or double quotes. They allow:
- String interpolation via
${expression}without messy+concatenation. - Multi-line strings without needing
\nescape characters. - Tagged templates, where a function parses the template literal and its interpolated values.
const user = "Alice";
const items = 3;
const summary = `Hello ${user}, you have ${items} items in your cart.`;
5. What is destructuring assignment for arrays and objects?
Destructuring unpacks values from arrays or properties from objects into distinct variables in a single statement. It also supports default values, renaming object properties, and nested extraction.
// Array destructuring
const [first, , third = "default"] = ["a", "b"]; // first = 'a'
// Object destructuring with renaming and default
const profile = { username: "jdoe" };
const { username: handle, role = "member" } = profile; // handle = 'jdoe'
6. What is the difference between the spread operator and rest parameters?
Both use the ... syntax, but serve opposite roles:
- Spread operator: Expands an iterable (like an array or string) or object properties into individual elements/entries—useful for shallow copying, merging, or passing arguments to functions.
- Rest parameters: Collects multiple remaining arguments or properties into a single array or object.
// Spread
const nums = [1, 2];
const combined = [...nums, 3, 4]; // [1, 2, 3, 4]
// Rest
function sum(multiplier, ...values) {
return values.reduce((acc, n) => acc + n * multiplier, 0);
}
7. How do default parameters work in ES6?
Default parameters let you assign fallback values to function parameters when no argument or undefined is passed. Passing null does not trigger the default value because null is an explicit value rather than undefined.
function greet(name = "Guest") {
return `Welcome, ${name}`;
}
greet(); // "Welcome, Guest"
greet(undefined); // "Welcome, Guest"
greet(null); // "Welcome, null"
8. How do ES6 Map and Set differ from plain objects and arrays?
Mapstores key-value pairs where keys can be any data type (including objects or functions), preserves insertion order, and provides.sizeand clean iteration methods. Plain objects restrict keys to strings or symbols and can collide withObject.prototypekeys.Setstores a collection of unique values (primitives or object references) in insertion order, making deduplication straightforward.
const uniqueIds = new Set([1, 2, 2, 3]); // Set(3) { 1, 2, 3 }
const cache = new Map();
const keyObj = { id: 42 };
cache.set(keyObj, "cached-record");
9. How do ES6 classes and extends / super work under the hood?
ES6 class syntax is primarily syntactic sugar over JavaScript's existing prototypal inheritance model. A class has a constructor method, prototype methods, optional static methods, and uses extends for inheritance and super(...) to invoke the parent constructor or parent methods.
class Animal {
constructor(name) {
this.name = name;
}
speak() {
return `${this.name} makes a sound.`;
}
static have_baby(name) {
return new Animal(name); // call it by `Animal.have_baby('mal')`
}
}
class Dog extends Animal {
constructor(name, breed) {
super(name);
this.breed = breed;
}
speak() {
return `${super.speak()} (${this.breed})`;
}
}
10. What are Promises, and how do they improve upon callbacks?
A Promise represents the eventual completion (or failure) of an asynchronous operation and its resulting value. A promise is always in one of three states: pending, fulfilled, or rejected.
Compared to deeply nested callbacks ("callback hell"), promises allow sequential chaining with .then(), centralized error handling with .catch(), and clean composition with helpers like Promise.all()—and later enabled async/await syntax.
function fetchUser(id) {
return new Promise((resolve, reject) => {
setTimeout(() => {
if (!id) return reject(new Error("Missing user ID"));
resolve({ id, name: "Jane" });
}, 200);
});
}
// it will finally log `Jane`
fetchUser(1)
.then((user) => console.log(user.name))
.catch((err) => console.error(err.message));
// it will finally log `Missing user ID` since !0 is true.
fetchUser(0)
.then((user) => console.log(user.name))
.catch((err) => console.error(err.message));