JavaScriptEs6 Featuresbeginner

ES6 Interview Questions and Answers

The modern JavaScript features interviewers expect you to use daily — spread and rest, destructuring, template literals, arrow functions, modules, WeakMap and optional chaining — with clear answers and code.

Published
TL;DR – Quick Answer

ES6 interview questions check that you write modern JavaScript: spread and rest, object and array destructuring, template literals, arrow functions and their this behaviour, ES modules versus CommonJS, Map and WeakMap, and the ES2020 operators ?. and ??. Interviewers usually ask how a feature differs from the older way of doing the same thing.

On This Page

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 — this inside it will not be the object, because arrows take this from 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 ?? c is 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?
let and const, arrow functions, template literals, destructuring, spread and rest, classes, modules, promises, Map and Set. Interviewers expect you to use them naturally in live coding and to explain how each differs from the older approach.
Is ES6 the same as ES2015?
Yes. ES6 was officially named ECMAScript 2015. After it, the standard moved to yearly releases — ES2016, ES2017 and so on — so features such as async/await (ES2017) and optional chaining (ES2020) are often loosely called ES6+ features.
What is the difference between spread and rest?
They use the same three dots but do opposite jobs. Rest collects several values into one array, in function parameters or destructuring. Spread expands an array or object into separate values, in calls, array literals and object literals.
When should I not use an arrow function?
Avoid arrow functions for object methods that need this, for constructors (they cannot be used with new), and for event handlers where you need this to be the element. Use them for short callbacks and when you want to keep the outer this.
Do all browsers support ES6 now?
All modern browsers support ES6 and most later features. Teams still use build tools such as Babel or a bundler to support very old browsers and to use the newest syntax before every browser ships it.
What is the difference between Map and a plain object?
A Map accepts keys of any type, keeps insertion order, has a size property and is designed for frequent additions and removals. A plain object only has string or symbol keys and inherits properties from its prototype unless created with Object.create(null).

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

Apply for Demo Class →
Siva Prasad Galaba
Founder, CodeBegun · Staff Engineer

Founder of CodeBegun. 15+ years building Java systems at companies like Crunchyroll. Teaches Java, Spring Boot and system design the way the industry actually works, and mentors students through projects, mock interviews and placement preparation.

Technically reviewed by CodeBegun Technical TeamLast reviewed 28 November 2026 LinkedIn
Chat with us