ES6 and the yearly releases after it changed how JavaScript is written, and interviewers now treat these features as basic knowledge. This guide covers the eight that come up most — spread and rest, destructuring, template literals, arrow functions, modules, Map and WeakMap, and optional chaining with nullish coalescing.
Why interviewers ask about ES6 features
Modern codebases use these features on every line, so an interviewer wants proof you can read and write them fluently. The questions are usually comparisons: spread versus rest, arrow versus regular functions, ?? versus ||, ES modules versus require.
Those comparisons reveal whether you understand the trade-off or only the syntax. Knowing that an arrow function has no own this explains a whole category of bugs; knowing the syntax alone does not.
How to answer these questions
For each feature, give the one-line purpose, show the before-and-after code, and name the pitfall. "Spread makes a shallow copy, so nested objects are still shared" is the kind of detail that turns a correct answer into a strong one.
If you learned the basics first, link back to them: destructuring and spread build directly on how JavaScript handles values and references, covered in the JavaScript basics guide.
Q1. What is the spread operator and how is it used?
The spread operator (...) expands an iterable — an array, string or object — into individual elements.
// Arrays
const a = [1, 2];
const b = [...a, 3, 4]; // [1, 2, 3, 4]
// Objects (shallow clone)
const obj = { x: 1 };
const copy = { ...obj, y: 2 }; // { x: 1, y: 2 }
// Function arguments
Math.max(...[3, 1, 4, 1, 5]); // 5
Interview note: Trap: "is
{ ...obj }a deep copy?" No — it is shallow, so nested objects are still shared — the advanced JavaScript guide covers deep copies.
Q2. What is the rest parameter syntax?
Rest parameters (...args) collect the remaining arguments of a function into a real array — unlike the old arguments object, which is only array-like.
function sum(...nums) {
return nums.reduce((acc, n) => acc + n, 0);
}
sum(1, 2, 3, 4); // 10
// First argument named, the rest captured
function first(head, ...tail) {
return { head, tail };
}
first(1, 2, 3); // { head: 1, tail: [2, 3] }
Interview note: Follow-up: "spread vs rest — same syntax, what is the difference?" Rest collects values into an array (in parameters and destructuring); spread expands an array or object into separate values.
Q3. What is destructuring assignment?
Destructuring unpacks values from arrays, or properties from objects, into separate variables — with optional defaults and rest.
// Array destructuring
const [a, b, ...rest] = [1, 2, 3, 4];
// a=1, b=2, rest=[3,4]
// Object destructuring
const { name, age = 18 } = { name: "Ravi" };
// name="Ravi", age=18 (default)
// In function parameters
function greet({ name, city = "Hyderabad" }) {
return `${name} from ${city}`;
}
Q4. What are template literals?
Template literals are backtick strings that support embedded expressions with ${}, multi-line text and tagged templates.
const name = "CodeBegun";
const msg = `Hello, ${name}!`; // "Hello, CodeBegun!"
// Multi-line without \n
const html = `
<div>
<p>${msg}</p>
</div>
`;
console.log(`2 + 2 = ${2 + 2}`); // "2 + 2 = 4"
Q5. What are arrow functions and how do they differ from regular functions?
Arrow functions are a concise ES6 syntax with no own this — they inherit this from the surrounding scope. They also have no arguments object, no prototype and cannot be used with new.
const add = (a, b) => a + b;
const obj = {
name: "CB",
greet() {
setTimeout(() => {
console.log(this.name); // "CB" — the arrow captures the outer this
}, 100);
},
};
Interview note: Trap: "should you use an arrow function as an object method?" Usually not —
thisinside it will not be the object, because arrows takethisfrom where they are defined.
Q6. What is the difference between CommonJS modules and ES modules?
CommonJS (require / module.exports) loads modules synchronously and dynamically and is Node.js's original system. ES modules (import / export) are static — analysed before the code runs — which enables tree shaking, and they are the standard for browsers and modern Node.
// CommonJS
const fs = require("fs");
module.exports = { readFile: fs.readFileSync };
// ES module
import { readFileSync } from "fs";
export const readFile = readFileSync;
Q7. What is a WeakMap and how is it different from Map?
A Map accepts any key, is iterable, has .size and holds keys strongly. A WeakMap accepts only objects as keys, is not iterable, has no .size, and holds keys weakly — so a key object can be garbage-collected.
Use a WeakMap to attach private data to objects, or to cache values that should disappear when the object is no longer used.
Q8. What are optional chaining (?.) and nullish coalescing (??)?
?. stops and returns undefined when the value before it is null or undefined, instead of throwing a TypeError. ?? returns its right-hand side only when the left side is null or undefined — unlike ||, which also replaces 0, "" and false.
const user = { profile: null };
user.profile?.name; // undefined (no TypeError)
user.getAge?.(); // undefined — the method does not exist
const count = 0;
count || 10; // 10 — 0 is falsy
count ?? 10; // 0 — 0 is not null or undefined
Both arrived in ES2020 and replace long chains of a && a.b && a.b.c checks and default values that wrongly overwrite 0 or an empty string.
Interview note: Trap: "can you mix
??with||without brackets?" No —a || b ?? cis a SyntaxError. You must add parentheses to make the intent explicit.
How to prepare
Refactor a small piece of old-style code — var, string concatenation, arguments, require — into modern syntax, and explain each change out loud as if to an interviewer.
Then continue with closures and functions and promises and async/await, where these features appear inside harder questions.
Frequently Asked Questions
What are the most important ES6 features for interviews?
Is ES6 the same as ES2015?
What is the difference between spread and rest?
When should I not use an arrow function?
Do all browsers support ES6 now?
What is the difference between Map and a plain object?
Want to Build Your Career in Java Full Stack with AI?
Join CodeBegun and train with working industry engineers — Check the Java Full Stack training details

