Every JavaScript interview starts with the basics, because they show in a few minutes whether you have actually written and debugged the language. This guide covers the eight fundamentals interviewers ask first — data types, var, let and const, hoisting, the temporal dead zone, equality and coercion — with answers you can say out loud and code you can write on a whiteboard.
Why interviewers ask about JavaScript basics
Basic questions are not easy questions. JavaScript lets you do things that other languages forbid — use a variable before it is declared, compare a string to a number, read typeof null as "object" — and interviewers use those surprises to see whether you know the rules or only the happy path.
A fresher who can explain why let throws where var gives undefined is far more convincing than one who recites definitions. If you are still deciding whether JavaScript is the right path, the JavaScript developer roadmap shows what the role expects.
How to answer these questions
Answer in three beats: the rule in one line, a two-line example, and the bug the rule prevents. For output questions, walk through the code line by line instead of jumping to the result — interviewers care about the reasoning.
When you are unsure, say what you would check in the console. Admitting that {} + [] depends on how the engine parses the line, and explaining why, is a stronger answer than a confident guess.
Q1. What are the key features of JavaScript?
JavaScript is a lightweight, interpreted, high-level language with dynamic typing, first-class functions, prototype-based objects and an event-driven, asynchronous model that runs on a single thread.
- Dynamic typing — types are resolved at runtime.
- First-class functions — functions are values; pass them around like any other object.
- Prototype-based OOP — objects inherit directly from other objects via the prototype chain.
- Event-driven and asynchronous — callbacks, promises and async/await enable non-blocking code.
- Single-threaded — one call stack, but the event loop gives the illusion of concurrency.
- Universal runtime — runs in browsers (V8, SpiderMonkey) and on the server (Node.js, Deno).
Interview note: Follow-up: "if JavaScript is single-threaded, how does it handle many requests?" The event loop hands slow work (timers, network, I/O) to the runtime and runs the callbacks later, so the main thread is never blocked waiting.
Q2. What are the JavaScript data types?
JavaScript has eight data types: seven primitives — string, number, bigint, boolean, undefined, null, symbol — and one non-primitive, object.
Arrays, functions, dates and maps are all objects. Use typeof to check a type, and remember the historical quirk: typeof null === "object".
Interview note: Follow-up: "how do you check if something is an array?" Use
Array.isArray(value)—typeof []returns"object".
Q3. What is the difference between var, let and const?
var is function-scoped and can be re-declared; let and const are block-scoped and live in the temporal dead zone until declared. const also cannot be reassigned — though the object it holds can still be mutated.
var— function-scoped, hoisted and initialised asundefined, can be re-declared and reassigned.let— block-scoped, hoisted but stays in the Temporal Dead Zone until the declaration line, can be reassigned but not re-declared.const— block-scoped, same TDZ behaviour, cannot be reassigned or re-declared.
var x = 1;
{
var x = 10; // same variable — overwrites outer x
let y = 20; // block-scoped, invisible outside
}
console.log(x); // 10
console.log(y); // ReferenceError
Interview note: Trap: "can you push to a
constarray?" Yes —conststops reassignment of the variable, not mutation of the value it points to.
Q4. What is hoisting in JavaScript?
Hoisting is the engine moving declarations to the top of their scope before code runs. Only the declaration is hoisted, not the initialisation — so var reads as undefined, function declarations work early, and let/const throw.
console.log(a); // undefined (var is declared but not yet assigned)
var a = 5;
greet(); // works — function declarations are fully hoisted
function greet() { console.log("Hello"); }
console.log(b); // ReferenceError — let stays in the TDZ
let b = 10;
Q5. What is the Temporal Dead Zone (TDZ)?
The TDZ is the stretch between the start of a block and the line where a let or const variable is declared. Accessing the variable inside it throws a ReferenceError.
{
// TDZ starts for x
console.log(x); // ReferenceError: Cannot access 'x' before initialization
let x = 10; // TDZ ends here
console.log(x); // 10
}
The TDZ exists to catch the bugs that var's silent undefined hoisting would hide.
Q6. What is the difference between == and ===?
== is loose equality and converts types before comparing; === is strict equality and compares value and type with no conversion.
0 == false // true (false is coerced to 0)
0 === false // false (different types)
"5" == 5 // true
"5" === 5 // false
Always prefer === to avoid subtle coercion bugs.
Interview note: Follow-up: "is there any case where
==is useful?"value == nullchecks for bothnullandundefinedin one comparison — the one idiom many style guides allow.
Q7. What is the difference between null and undefined?
undefined means a variable was declared but never assigned — JavaScript sets it automatically. null is an intentional "no value" that the developer sets.
let a; // undefined
let b = null; // intentionally empty
typeof undefined // "undefined"
typeof null // "object" ← legacy quirk in JS
Q8. What is type coercion in JavaScript?
Type coercion is the automatic conversion of a value from one type to another whenever you mix types in an operation.
"5" + 2 // "52" — number coerced to string
"5" - 2 // 3 — string coerced to number
true + 1 // 2 — boolean coerced to number
[] + {} // "[object Object]"
{} + [] // 0 (parsed differently by the engine)
The + operator prefers strings: if either side is a string, it concatenates. Other arithmetic operators convert to numbers.
How to prepare
Open the browser console and type every snippet in this guide yourself, predicting the output before you press Enter. The ones you get wrong are the ones to revise.
When these feel easy, move on to ES6 interview questions and closures and functions, the next two topics interviewers reach for. The JavaScript jobs for freshers guide explains which roles test these basics hardest.
Frequently Asked Questions
What JavaScript basics are asked most for freshers?
Is JavaScript compiled or interpreted?
Should I still use var in modern JavaScript?
Why does typeof null return "object"?
What is the difference between undeclared and undefined?
How do I explain hoisting simply?
Want to Build Your Career in Java Full Stack with AI?
Join CodeBegun and train with working industry engineers — See the Java Full Stack course in Hyderabad

