D
DevPrepSystematic Prep
JAVASCRIPT · EASY CODEX

JavaScript Interview Questions — Easy

Core concepts, definitions, basic syntax, and first principles expected in round 1 screening.

50 Theory Questions7 Implementation Folios5 Free Model Answers
THEORY QUESTIONS & SOLUTIONSShowing 5 of 50 questions
Q1Explain the differences between Primitive and Reference types. How are they stored in memory, and how does `typeof` differ from `instanceof`?
  • Primitive Types: undefined, null, boolean, number, string, symbol, and bigint. Stored directly in the stack memory. They are immutable and compared by value.
  • Reference Types: Objects, arrays, functions, maps, and sets. Stored in the heap memory; the variable in the stack holds a pointer/reference to the heap location. They are mutable and compared by reference pointer.
  • typeof: An operator that returns a string representing the data type of an unevaluated operand. Best for primitives (e.g., typeof "hello" === "string"), but returns "object" for null, arrays, and plain objects.
  • instanceof: An operator that tests whether the prototype property of a constructor appears anywhere in the prototype chain of an object (e.g., arr instanceof Array === true). Only works for objects/reference types.
Q2What is Scope in JavaScript? Compare Global, Function, and Block scopes.
  • Scope: Determines the accessibility (visibility) of variables within different parts of the code.
  • Global Scope: Variables declared outside any function or block. Accessible from anywhere in the application.
  • Function (Local) Scope: Variables declared inside a function (using var, let, or const). Accessible only within that function.
  • Block Scope: Variables declared inside a block {} using let or const. They cannot be accessed outside that block. var does not respect block scope.
Q3Explain Hoisting and the Temporal Dead Zone (TDZ).
  • Hoisting: The default behavior of the JS interpreter where variable and function declarations are moved to the top of their containing scope before code execution.
  • var hoisting: Initialized with undefined. Accessible before declaration.
  • let/const hoisting: Hoisted but not initialized. Accessing them before declaration throws a ReferenceError.
  • Function hoisting: Full function declarations are hoisted, making them callable before their definition in the code. Function expressions are not.
  • Temporal Dead Zone (TDZ): The period between block entry and variable initialization where accessing a let or const variable throws a ReferenceError.
Q4Compare `var`, `let`, and `const` in terms of scoping, hoisting, and re-assignment.
Feature var let const
Scope Function scope Block scope Block scope
Hoisting Yes (initialized as undefined) Yes (uninitialized, TDZ active) Yes (uninitialized, TDZ active)
Re-assignment Allowed Allowed Not Allowed
Redeclaration Allowed within same scope Not Allowed Not Allowed
Q5What is a Closure? Provide a short example of why it is useful.
  • Closure: A function that retains access to its lexical scope (outer variables) even when the function is executed outside that scope.
  • Mechanism: Created automatically when an inner function is defined inside an outer function, capturing the outer function's environment.
  • Use Cases: Data privacy/encapsulation (private variables), state maintenance, currying, and memoization.
  • Example:
    function createCounter() {
      let count = 0;
      return () => ++count;
    }
    const counter = createCounter();
    console.log(counter()); // 1
    console.log(counter()); // 2
    

Unlock the remaining 52 JavaScript (Easy) questions

You've completed the 5 free sample questions. Get unrestricted lifetime access to every question, model answer, implementation challenge, and all 27+ technologies for a single payment.

₹399 India / $9 International · One-time settlement · Zero subscription

CROSS-DIFFICULTY NAVIGATION

Continue Preparing JavaScript

JavaScript Interview Questions (Easy) | DevPrep | DevPrep