JavaScript Basic Interview Questions: Types & Scope

JavaScript basic interview questions open almost every technical screening, not because interviewers lack imagination, but because misconceptions here propagate into every line of production code. Understanding how V8 stores primitives in stack memory while referencing objects in the heap is the foundation of predicting mutation and debugging memory leaks.

These lessons eliminate guessing from type coercion and equality comparisons. Step through the exact ToPrimitive conversions, inspect Temporal Dead Zone boundaries, and master safe object copying strategies required by high-bar frontend interview panels.

JavaScript Basic Interview Questions: 16 lessons

1. Primitive vs Reference Types
Interactive Ready

Data types in JavaScript split into primitives and reference types: 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. Variable assignment and function arguments in JavaScript are always passed by value; for objects, the value passed is the memory reference itself.

Easy100% Free
2. Type Coercion & Equality
Interactive Ready

Type coercion is JavaScript's automatic or implicit conversion of values between data types during operations. The binary + operator favors string concatenation if either operand is a string, arithmetic operators force numeric conversion via ToNumber, and loose equality (==) coerces operands to primitives and numbers before comparing.

Medium100% Free
3. Scope, Hoisting & TDZ
Interactive Ready

Hoisting in JavaScript is the engine's behavior during compilation where variable and function declarations are registered in their environment records before code executes. var is hoisted and initialized to undefined, while let and const are hoisted without initialization and remain in the Temporal Dead Zone (TDZ) until evaluation.

Medium100% Free
4. Objects, Arrays & Copying
Interactive Ready

Shallow copy vs deep copy in JavaScript starts from one fact: objects and arrays are reference types stored in heap memory, where variable assignments create memory aliases. Modifying an aliased object affects all references, necessitating defensive cloning techniques like Object.assign, the spread operator, or structuredClone to maintain data immutability.

Medium100% Free
5. Equality, Coercion & Comparisons
Interactive Ready

JavaScript defines four distinct equality algorithms: loose equality (==), strict equality (===), SameValueZero (used by Map, Set, and includes), and SameValue (used by Object.is). Relational operators (<, >=) coerce null to 0, whereas loose equality does not, producing counterintuitive comparisons.

Medium100% Free
6. Memory Management & Garbage Collection
Interactive Ready

Garbage collection in JavaScript is the last stage of an automated memory lifecycle of allocation, usage, and release, based on object reachability from root references. The V8 engine utilizes generational Mark-and-Sweep and Scavenger algorithms to reclaim memory from unreferenced heap objects, preventing memory leaks.

Hard100% Free
7. Callback Functions
Interactive Ready

A callback function in JavaScript is a function passed as an argument to another function, which calls it back later. Some APIs call it synchronously, like Array.prototype.map, and some asynchronously, like setTimeout or an event listener, so the same pattern can run now or after the current code finishes.

Easy100% Free
8. for...in vs for...of Loops
Interactive Ready

The for in loop in JavaScript walks the enumerable string keys of an object, including keys it inherits through the prototype chain. Own integer-like keys come first in ascending order, then other string keys in insertion order, then inherited ones. For arrays it gives the indexes as strings, so use for...of to loop over values.

Easy100% Free
9. String Methods
Interactive Ready

String methods in JavaScript, such as slice, substring, split, indexOf, replace, replaceAll, trim, includes and at, all return a new value: strings are immutable, so no method changes the original string. The classic traps are slice vs substring with negative indexes, replace changing only the first match, and case-sensitive searches.

Easy100% Free
10. Higher Order Functions
Interactive Ready

Higher order functions in JavaScript are functions that take another function as an argument, return a function, or both. map, filter, reduce, setTimeout and addEventListener take functions; function factories and decorators return them. They work because functions are first-class values, and the returned functions keep access to their outer variables through closures.

Easy100% Free
11. Arrays
Interactive Ready

An array in JavaScript is an ordered, zero-indexed list of values; it is an object with numeric keys and a length property, so typeof gives 'object' and Array.isArray is the real check. Some methods mutate it (push, splice, sort, reverse) and others return a new array (slice, map, filter, concat, toSorted).

Easy100% Free
12. Loops
Interactive Ready

Loops in JavaScript repeat code: for runs a counter loop, while repeats while a condition holds, do...while runs its body at least once, for...of walks the values of an iterable and for...in walks an object's keys. In a for loop, let gives each iteration its own variable, while var shares one, which matters when callbacks run later.

Easy100% Free
13. Operators
Interactive Ready

Operators in JavaScript include arithmetic (+, -, *, /, %, **), assignment, comparison, logical (&&, ||, !, ??), optional chaining (?.) and typeof. The classic traps are that + concatenates when either side is a string, || falls back on any falsy value while ?? only on null or undefined, and typeof null is 'object'.

Easy100% Free
14. Functions
Interactive Ready

Functions in JavaScript are reusable blocks of code that are also values. A function declaration is hoisted with its body, so it can be called before its line; a function expression or arrow function follows the rules of the variable holding it. Default parameters apply only to undefined, and rest parameters collect extra arguments into an array.

Easy100% Free
15. Variables
Interactive Ready

Variables in JavaScript are declared with var, let or const. var is function-scoped and starts as undefined when hoisted; let and const are block-scoped and throw a ReferenceError if read before their line. const prevents reassignment of the variable, but the object or array it holds can still be changed.

Easy100% Free
16. Objects
Interactive Ready

Objects in JavaScript are collections of key-value pairs whose keys are strings or symbols. Variables hold references to objects, so assigning or passing an object shares it and === compares references, not contents. Copy with spread or structuredClone, and use a Map when you need objects as keys.

Easy100% Free