Autocoder

JavaScript ES6 Interview Questions

Last updated 2026-11-19

ES6, officially ECMAScript 2015, changed how JavaScript is written, and interviews still use it as a checklist of modern fluency. You are expected to explain destructuring, default parameters, template literals, modules and classes, and to know the data structures and protocols the release introduced.

The questions below also cover useful features from later editions, such as optional chaining and Object.entries, since interviewers rarely separate them. Each answer includes a short example that you can run to confirm the output.

LevelFresher to 3 years
FocusES2015 and later syntax and built-ins
RuntimeBrowser and Node.js 18 or later

A quick map of the release

Syntax: let and const, arrow functions, template literals, destructuring, default and rest parameters, spread, classes, modules, for...of. Built-ins: Promise, Map, Set, WeakMap, WeakSet, Symbol, Proxy, Reflect and new Array and Object helpers. Protocols: iterators and generators.

Related pages

See hoisting and scope for let and const detail, promises for async features, and how to crack a JavaScript interview for the broader plan.

JavaScript ES6 Interview Questions: questions with worked answers

  1. 1

    What are the main features introduced in ES6?

    easy

    let and const, arrow functions, template literals, destructuring, default parameters, rest and spread, classes, modules with import and export, Promises, Map and Set, WeakMap and WeakSet, Symbol, iterators and generators, for...of, Proxy and Reflect, and shorthand syntax for object literals. Later releases added async and await, optional chaining, nullish coalescing, Object.entries and flat among many others.

  2. 2

    How does destructuring work for arrays and objects?

    easy

    Array destructuring unpacks by position and object destructuring by property name. Both support defaults, renaming, nesting and rest. It is common for function parameters and for swapping variables without a temporary.

    javascript
    const [a, , c = 9, ...rest] = [1, 2, undefined, 4, 5];
    console.log(a, c, rest);                 // 1 9 [ 4, 5 ]
    const { x, y: why = 0, ...others } = { x: 1, z: 3, w: 4 };
    console.log(x, why, others);             // 1 0 { z: 3, w: 4 }
    let p = 1, q = 2;
    [p, q] = [q, p];
    console.log(p, q);                       // 2 1
  3. 3

    What are the differences between arrow functions and regular functions?

    medium

    Arrow functions have a shorter syntax with implicit return, take this and arguments lexically from the enclosing scope, cannot be used as constructors with new, have no prototype property and cannot be generators. Regular functions have their own this, an arguments object and can be called with new. Use arrows for callbacks and regular functions or method syntax for object methods and constructors.

    javascript
    const sq = (x) => x * x;
    const obj = () => ({ ok: true });    // parentheses to return an object literal
    function f() { return arguments.length; }
    const g = (...a) => a.length;
    console.log(sq(4), obj(), f(1, 2), g(1, 2, 3));   // 16 { ok: true } 2 3
    try { new sq(); } catch (e) { console.log(e.message); }   // sq is not a constructor
  4. 4

    What are template literals and tagged templates?

    easy

    Template literals use backticks, allow multi-line strings and embed expressions with a dollar sign and braces. A tagged template puts a function name before the literal, and the function receives the string pieces and the evaluated values, so it can sanitise or format them. Libraries such as styled-components and SQL helpers use this.

    javascript
    const n = 3;
    console.log(`total: ${n * 2}`);        // total: 6
    const tag = (s, ...v) => s.raw.join("|") + v.join(",");
    console.log(tag`a${1}b${2}c`);          // a|b|c1,2
  5. 5

    What are default parameters, and when are they evaluated?

    medium

    A default applies when the argument is undefined, not for null or other falsy values. The default expression is evaluated at call time, fresh for each call, unlike Python, so mutable defaults are safe. Defaults can refer to earlier parameters.

    javascript
    function f(a, b = a * 2, list = []) { list.push(b); return list; }
    console.log(f(1), f(1));        // [ 2 ] [ 2 ]
    console.log(f(1, null));        // [ null ]
    console.log(f(1, undefined));   // [ 2 ]
  6. 6

    What are the differences between Map and Object, and between Set and Array?

    medium

    A Map accepts keys of any type, keeps insertion order, has a size property and iterates directly, and it does not have inherited keys. A plain object coerces keys to strings or symbols and has a prototype. A Set stores unique values and checks membership in near constant time, whereas an Array allows duplicates and searches linearly. Both Map and Set compare keys with SameValueZero, so NaN equals NaN.

    javascript
    const m = new Map([[1, "a"], ["1", "b"]]);
    console.log(m.size, m.get(1), m.get("1"));       // 2 a b
    const s = new Set([1, 2, 2, NaN, NaN]);
    console.log([...s], s.has(NaN));                  // [ 1, 2, NaN ] true
    console.log([...new Set("hello")].join(""));     // helo
  7. 7

    What is the difference between WeakMap and Map?

    medium

    A WeakMap holds its keys weakly: keys must be objects, and an entry does not prevent the key from being garbage collected. WeakMaps are not iterable and have no size, since contents can disappear at any time. They are used for private data and caches attached to objects without causing memory leaks.

  8. 8

    How do ES modules work, and how do they differ from CommonJS?

    medium

    ES modules use static import and export, are parsed before running, support tree shaking, are strict by default, have their own scope and export live bindings. CommonJS uses require and module.exports at runtime, can be called conditionally, and exports copies of values at the time of require. Default exports can be imported under any name, while named exports must match, or be renamed with as.

    javascript
    // math.mjs
    export const PI = 3.14;
    export default function add(a, b) { return a + b; }
    // main.mjs
    // import add, { PI } from "./math.mjs";
    // const lazy = await import("./math.mjs");   // dynamic import
  9. 9

    What is a Symbol, and what is it for?

    medium

    A Symbol is a unique, immutable primitive often used as a property key that cannot collide with string keys and does not show up in for...in or Object.keys. Well-known symbols such as Symbol.iterator and Symbol.toPrimitive let objects hook into language behaviour.

    javascript
    const id = Symbol("id");
    const o = { [id]: 1, name: "x" };
    console.log(Object.keys(o), o[id]);         // [ 'name' ] 1
    console.log(Symbol("a") === Symbol("a"));   // false
  10. 10

    How do iterators and generators work in ES6?

    medium

    An object is iterable if it has a Symbol.iterator method returning an iterator, an object with next() that returns value and done. Generator functions, declared with an asterisk, produce iterators using yield and pause between values. They make lazy sequences and custom iteration short.

    javascript
    const range = {
      from: 1, to: 3,
      *[Symbol.iterator]() { for (let i = this.from; i <= this.to; i++) yield i; },
    };
    console.log([...range]);          // [ 1, 2, 3 ]
    const [first, ...others] = range;
    console.log(first, others);       // 1 [ 2, 3 ]
  11. 11

    What are Proxy and Reflect used for?

    hard

    A Proxy wraps an object and intercepts operations such as get, set, has and deleteProperty with handler traps, allowing validation, logging, defaults and reactive systems. Reflect provides the default behaviour for each trap as functions, so a trap can forward the operation. Vue 3 reactivity is built on Proxy.

    javascript
    const target = { a: 1 };
    const p = new Proxy(target, {
      get(t, k, r) { return k in t ? Reflect.get(t, k, r) : `no ${String(k)}`; },
      set(t, k, v) { if (typeof v !== "number") throw new TypeError("number only"); t[k] = v; return true; },
    });
    console.log(p.a, p.b);   // 1 no b
    p.c = 5;
    console.log(target.c);   // 5
  12. 12

    What are object shorthand, computed property names and Object helpers?

    medium

    Shorthand lets you write { a, b } instead of { a: a, b: b } and method syntax without function. Computed names put an expression in brackets. Object.entries, Object.fromEntries, Object.assign and Object.freeze are frequent tools, and Object.groupBy exists in the latest runtimes.

    javascript
    const k = "id", a = 1;
    const o = { a, [k + "2"]: 2, hi() { return "hi"; } };
    console.log(o);                                   // { a: 1, id2: 2, hi: [Function: hi] }
    console.log(Object.fromEntries(Object.entries({ x: 1, y: 2 }).map(([k, v]) => [k, v * 2])));
    // { x: 2, y: 4 }
  13. 13

    What do for...of, Array.from and the spread operator accept?

    medium

    All work with iterables: arrays, strings, Maps, Sets, generators, arguments and NodeLists. Array.from also accepts array-likes, objects with length and indices, plus an optional mapping function. Spread on an object is separate and copies own enumerable properties.

    javascript
    console.log(Array.from("abc"));                     // [ 'a', 'b', 'c' ]
    console.log(Array.from({ length: 3 }, (_, i) => i * i)); // [ 0, 1, 4 ]
    console.log([..."hi", ...new Set([1, 1, 2])]);      // [ 'h', 'i', 1, 2 ]
  14. 14

    Predict the output: temporal dead zone and typeof with let.

    hard

    let and const bindings exist from the start of the block but cannot be accessed until the declaration executes. That period is the temporal dead zone, and even typeof throws inside it, unlike for a truly undeclared name where typeof returns 'undefined'.

    javascript
    console.log(typeof notDeclared);       // undefined
    {
      try { typeof x; } catch (e) { console.log(e.name); }   // ReferenceError
      let x = 1;
    }

Frequently asked questions

Is ES6 the same as ES2015?

Yes. ECMAScript 6 was renamed ES2015 when the committee moved to yearly releases, so ES2016 and later are small annual additions.

Do I still need Babel for ES6?

Modern browsers and Node support ES2015 and later almost fully, so transpiling is needed mainly for very old targets or for experimental syntax.

When should I use let versus const?

Use const by default and let only for variables that must be reassigned. Avoid var in new code.

What is the difference between export default and named exports?

A module has at most one default export, imported under any name, and any number of named exports, imported with their names inside braces.

Related guides

More in Programming Language Interview Questions by Language

See all in this section