JavaScript Interview Questions for Freshers

The JavaScript questions freshers are most often asked, with a short answer for each. Every question links to a full lesson with the traps interviewers look for and a step-by-step trace of the code.

  1. 01 · JavaScript Fundamentals for Frontend Interviews · Easy

    Primitive vs Reference Types

    JavaScript primitives are immutable values stored directly by value, whereas reference types (objects, arrays, functions) are mutable entities stored on the heap and accessed via memory references.

    Full answer, traps and step-by-step trace
  2. 02 · JavaScript Fundamentals for Frontend Interviews · Medium

    Type Coercion & Equality

    Type coercion is JavaScript’s automatic or implicit conversion of values between data types during operations.

    Full answer, traps and step-by-step trace
  3. 03 · JavaScript Fundamentals for Frontend Interviews · Medium

    Scope, Hoisting & TDZ

    Hoisting is the JavaScript engine’s behavior during compilation where variable and function declarations are registered in their environment records before code executes.

    Full answer, traps and step-by-step trace
  4. 04 · JavaScript Fundamentals for Frontend Interviews · Medium

    Objects, Arrays & Reference Semantics

    JavaScript objects and arrays are reference types stored in heap memory where variable assignments create memory aliases.

    Full answer, traps and step-by-step trace
  5. 05 · JavaScript Fundamentals for Frontend Interviews · Medium

    Equality, Coercion & Comparison Traps

    JavaScript defines four distinct equality algorithms: loose equality (==), strict equality (===), SameValueZero (used by Map, Set, and includes), and SameValue (used by Object.is).

    Full answer, traps and step-by-step trace
  6. 06 · Execution Contexts, Closures, and Object Prototypes · Medium

    Execution Context & Call Stack

    A JavaScript Execution Context is an internal runtime environment that tracks code evaluation, consisting of a Lexical Environment, Variable Environment, and ThisBinding.

    Full answer, traps and step-by-step trace
  7. 07 · Execution Contexts, Closures, and Object Prototypes · Medium

    Closures & Lexical Scope

    A closure is a function bundled with references to its surrounding lexical environment (its [[Environment]] internal slot).

    Full answer, traps and step-by-step trace
  8. 08 · Execution Contexts, Closures, and Object Prototypes · Medium

    this, call, apply & bind

    In JavaScript, the "this" keyword represents the evaluation context of a function call determined dynamically by the call-site: default binding (global/undefined), implicit binding (object before the dot), or explicit binding (via call, apply, or bind).

    Full answer, traps and step-by-step trace
  9. 09 · Execution Contexts, Closures, and Object Prototypes · Medium

    Prototypes & Inheritance

    JavaScript implements inheritance through prototype delegation where every object holds an internal [[Prototype]] link to another object.

    Full answer, traps and step-by-step trace
  10. 10 · Execution Contexts, Closures, and Object Prototypes · Medium

    Property Flags & Descriptors

    JavaScript property descriptors govern property behavior through attribute flags: value, writable, enumerable, and configurable.

    Full answer, traps and step-by-step trace
  11. 11 · The Event Loop, Microtasks, and Asynchronous Concurrency · Medium

    Promises & Chaining

    A Promise represents the eventual completion or failure of an asynchronous operation, existing in one of three states: pending, fulfilled, or rejected.

    Full answer, traps and step-by-step trace
  12. 12 · The Event Loop, Microtasks, and Asynchronous Concurrency · Medium

    async/await Internals

    async/await is syntactic sugar over Promises and Generators that allows writing asynchronous code with synchronous control flow.

    Full answer, traps and step-by-step trace
  13. 13 · The Event Loop, Microtasks, and Asynchronous Concurrency · Medium

    Promise Combinators (all, allSettled, race, any)

    Promise combinators coordinate collections of concurrent promises: Promise.all requires all to fulfill and fails fast on the first rejection; Promise.allSettled waits for all outcomes; Promise.race settles with the first settled promise; and Promise.any…

    Full answer, traps and step-by-step trace
  14. 14 · The Event Loop, Microtasks, and Asynchronous Concurrency · Medium

    Timers & Concurrency Control

    setTimeout and setInterval schedule callbacks in the macrotask queue to execute after a minimum delay once the call stack is clear.

    Full answer, traps and step-by-step trace
  15. 15 · Tricky JavaScript Output Prediction & Code Reasoning · Medium

    Hoisting & Scope Traps

    Function declarations hoist with their complete implementation and take precedence over var declarations during compilation.

    Full answer, traps and step-by-step trace
  16. 16 · JavaScript Utility Implementations and Standard Polyfills · Medium

    Debounce and Throttle Implementations

    Debounce delays function execution until a quiet period passes without new invocations, ideal for search autocomplete. Throttle limits function execution to at most once per time window, ideal for scroll, resize, and mousemove handlers.

    Full answer, traps and step-by-step trace
  17. 17 · JavaScript Utility Implementations and Standard Polyfills · Medium

    Flattening Nested Arrays

    Array flattening reduces multi-dimensional arrays into a single-level array. Native Array.prototype.flat(depth) flattens by a specified recursion depth while removing empty slots in sparse arrays, implemented recursively or iteratively via a stack.

    Full answer, traps and step-by-step trace
  18. 18 · JavaScript Utility Implementations and Standard Polyfills · Medium

    Higher-Order Functions & Currying

    Currying transforms a function of N arguments into a chain of unary functions via closures, executing when all arguments are collected. Function composition pipelines unary functions together, executing right-to-left for compose and left-to-right for pipe.

    Full answer, traps and step-by-step trace
  19. 19 · JavaScript Utility Implementations and Standard Polyfills · Medium

    JavaScript Array Methods

    Custom array polyfills replicate native ECMAScript array methods: map returns a new array of transformed elements, filter returns elements satisfying a predicate, and reduce accumulates elements into a single value while properly handling sparse arrays and…

    Full answer, traps and step-by-step trace
  20. 20 · Browser APIs, DOM Performance, and Client-Side Security · Medium

    DOM Events and Event Delegation

    DOM events propagate in three sequential phases: capturing (window down to target), target, and bubbling (target up to window).

    Full answer, traps and step-by-step trace
  21. 21 · Browser APIs, DOM Performance, and Client-Side Security · Medium

    DOM Traversal & Reflow

    DOM traversal navigates nodes in the document tree, while reflow is the browser’s expensive calculation of element geometry and layout.

    Full answer, traps and step-by-step trace
  22. 22 · Browser APIs, DOM Performance, and Client-Side Security · Medium

    Web Storage, Cookies & Persistence

    Web Storage (localStorage and sessionStorage) stores client-side key-value string pairs without sending data to servers, while HTTP Cookies store small snippets that are transmitted with every HTTP request.

    Full answer, traps and step-by-step trace
  23. 23 · Modern JavaScript: ES Modules, Iterators, and Weak Collections · Medium

    JavaScript Modules (ESM vs CommonJS)

    ES Modules use live bindings where imported identifiers reflect runtime changes in the exporting module, whereas CommonJS copies primitive values into module.exports.

    Full answer, traps and step-by-step trace
  24. 24 · Modern JavaScript: ES Modules, Iterators, and Weak Collections · Medium

    Iterators & Generators

    Iterators implement a next() method returning { value, done }. Generator functions (function*) provide pausabe, resumable execution using yield, enabling bidirectional data exchange and lazy evaluation of infinite streams.

    Full answer, traps and step-by-step trace
  25. 25 · Modern JavaScript: ES Modules, Iterators, and Weak Collections · Medium

    Maps, Sets, WeakMap & WeakSet

    Map supports arbitrary key types and maintains insertion order, while Set stores unique values using SameValueZero equality.

    Full answer, traps and step-by-step trace
  26. 26 · Modern JavaScript: ES Modules, Iterators, and Weak Collections · Medium

    JavaScript Classes & Inheritance

    JavaScript classes are syntactic sugar over prototype delegation, introducing strict mode execution, class TDZ, and non-enumerable prototype methods.

    Full answer, traps and step-by-step trace
  27. 27 · Modern JavaScript: ES Modules, Iterators, and Weak Collections · Medium

    Tagged Templates & Frontend Security

    Tagged template literals pass template strings and interpolated expressions to a tag function before string assembly, enabling automatic context-aware escaping to prevent DOM XSS vulnerabilities before injecting dynamic values into the DOM.

    Full answer, traps and step-by-step trace
  28. 28 · Debugging, Memory Leak Analysis, and Code Quality · Medium

    Error Handling & Debugging

    JavaScript manages runtime exceptions using try/catch/finally blocks. The finally block executes unconditionally for resource cleanup, overriding prior returns or throws, while asynchronous errors require Promise rejection handlers or async/await try/catch.

    Full answer, traps and step-by-step trace

Applying for the role too? Frontend developer resume examples