If you're prepping for a JavaScript interview, the fundamentals are where it all starts. Interviewers love probing this area because it separates people who've memorized syntax from people who actually understand how the language behaves under the hood.
This is Part 1 of an 8-part series covering JavaScript interview questions with detailed explanations. Let's dive in. 🚀
If you're prepping for a JavaScript interview, the fundamentals are where it all starts. Interviewers love probing this area because it separates people who've memorized syntax from people who actually understand how the language behaves under the hood.
This is Part 1 of an 8-part series covering JavaScript interview questions with detailed explanations. Let's dive in. 🚀
Q1. What are the primitive data types in JavaScript?
JavaScript has seven primitive types:
stringnumberbooleannullundefinedsymbolbigint
Primitives are immutable and are compared by value, not by reference.
Everything else—objects, arrays, and functions—is a reference type and is compared by reference (memory address).
Q2. What is the difference between null and undefined?
-
undefinedmeans a variable has been declared but not assigned a value, a function has no explicit return, or an object property doesn't exist. -
nullis an intentional assignment representing "no value."
typeof undefined; // "undefined"
typeof null; // "object" (a long-standing JavaScript bug)
Q3. What is the difference between == and ===?
=== (strict equality) compares both value and type.
== (loose equality) performs type coercion before comparison.
"5" == 5; // true
"5" === 5; // false
Best practice: Prefer === to avoid unexpected coercion.
Q4. What is NaN, and how do you correctly check for it?
NaN ("Not a Number") represents an invalid numeric result.
A unique property:
NaN !== NaN // true
Correct way to check:
Number.isNaN(NaN); // true
isNaN("hello"); // true (because of coercion)
Number.isNaN("hello"); // false
Q5. What is type coercion in JavaScript?
Type coercion is JavaScript automatically converting one type into another.
Examples:
"5" - 2; // 3
"5" + 2; // "52"
It can also be explicit:
Number("5");
String(5);
Boolean(1);
Q6. What are truthy and falsy values?
Falsy values are:
false
0
-0
0n
""
null
undefined
NaN
Everything else—including {} and []—is truthy.
Q7. What is the difference between var, let, and const?
| Keyword | Scope | Redeclare | Reassign |
|---|---|---|---|
var |
Function | ✅ | ✅ |
let |
Block | ❌ | ✅ |
const |
Block | ❌ | ❌ |
Notes:
-
varis initialized withundefined. -
letandconstexist in the Temporal Dead Zone until their declaration. -
constprevents reassignment, not object mutation.
Q8. What is variable hoisting?
Hoisting moves declarations to the top of their scope before execution.
console.log(a); // undefined
var a = 10;
With let and const:
console.log(a); // ReferenceError
let a = 10;
Q9. What is the Temporal Dead Zone (TDZ)?
The TDZ is the time between entering a scope and reaching a let or const declaration.
console.log(x); // ReferenceError
let x = 5;
Although x exists internally, it cannot be accessed until its declaration executes.
Q10. What is the difference between deep copy and shallow copy?
A shallow copy copies only the first level.
Nested objects remain shared.
const shallow = { ...original };
A deep copy duplicates every nested object.
const deep = structuredClone(original);
Final Thoughts
Mastering these JavaScript fundamentals is essential for technical interviews because they reveal how well you understand the language beyond syntax.
In Part 2, we'll cover Functions, Scope & Closures—including some of the most frequently asked JavaScript interview questions.
If this article helped, leave a ❤️ and follow for the rest of the series!
Top comments (0)