✅ 20 JavaScript Interview Questions
1. What are the different data types in JavaScript
• String, Number, Boolean, Undefined, Null, Object, Symbol, BigInt
Use
2. What is the difference between == and ===
•
•
3. What is hoisting in JavaScript
Variables and function declarations are moved to the top of their scope before execution.
Only declarations are hoisted, not initializations.
4. What is a closure
A function that remembers variables from its outer scope even after the outer function has finished executing.
Example:
5. What is the difference between var, let, and const
•
•
•
6. What is event delegation
Using a single event listener on a parent element to handle events from its child elements using
7. What is the use of promises in JavaScript
Handle asynchronous operations.
States: pending, fulfilled, rejected
Example:
8. What is async/await
Syntactic sugar over promises for cleaner async code
Example:
9. What is the difference between null and undefined
•
•
10. What is the use of arrow functions
Shorter syntax, no own
Example:
11. What is the DOM
Document Object Model — represents HTML as a tree structure. JavaScript can manipulate it using methods like
12. What is the difference between call, apply, and bind
•
•
•
13. What is the use of setTimeout and setInterval
•
•
14. What is the difference between stack and heap
• Stack: stores primitive values and function calls
• Heap: stores objects and reference types
15. What is the use of the spread operator (...)
Expands arrays/objects or merges them
Example:
16. What is the difference between map and forEach
•
•
17. What is the use of localStorage and sessionStorage
•
•
18. What is a prototype in JavaScript
Every object has a prototype — an object it inherits methods and properties from. Enables inheritance.
19. What is the difference between synchronous and asynchronous code
• Synchronous: executes line by line
• Asynchronous: executes independently, doesn’t block main thread
20. What are modules in JavaScript
Used to split code into reusable pieces
Example:
👍 React for more Interview Resources #javascript #interview #coding #webdev #frontend
1. What are the different data types in JavaScript
• String, Number, Boolean, Undefined, Null, Object, Symbol, BigInt
Use
typeof
to check a variable’s type.2. What is the difference between == and ===
•
==
compares values with type coercion•
===
compares both value and type (strict equality)3. What is hoisting in JavaScript
Variables and function declarations are moved to the top of their scope before execution.
Only declarations are hoisted, not initializations.
4. What is a closure
A function that remembers variables from its outer scope even after the outer function has finished executing.
Example:
function outer() {
let count = 0;
return function inner() {
count++;
console.log(count);
};
}
const counter = outer();
counter(); // 1
5. What is the difference between var, let, and const
•
var
: function-scoped, can be re-declared•
let
: block-scoped, can be updated•
const
: block-scoped, cannot be re-assigned6. What is event delegation
Using a single event listener on a parent element to handle events from its child elements using
event.target
.7. What is the use of promises in JavaScript
Handle asynchronous operations.
States: pending, fulfilled, rejected
Example:
fetch(url)
.then(res => res.json())
.catch(err => console.error(err));
8. What is async/await
Syntactic sugar over promises for cleaner async code
Example:
async function getData() {
const res = await fetch(url);
const data = await res.json();
console.log(data);
}
9. What is the difference between null and undefined
•
null
: intentional absence of value•
undefined
: variable declared but not assigned10. What is the use of arrow functions
Shorter syntax, no own
this
bindingExample:
const add = (a, b) => a + b;
11. What is the DOM
Document Object Model — represents HTML as a tree structure. JavaScript can manipulate it using methods like
getElementById
, querySelector
, etc.12. What is the difference between call, apply, and bind
•
call
: invokes function with arguments passed individually•
apply
: invokes function with arguments as array•
bind
: returns a new function with bound context13. What is the use of setTimeout and setInterval
•
setTimeout
: runs code once after delay•
setInterval
: runs code repeatedly at intervals14. What is the difference between stack and heap
• Stack: stores primitive values and function calls
• Heap: stores objects and reference types
15. What is the use of the spread operator (...)
Expands arrays/objects or merges them
Example:
const arr = [1, 2];
const newArr = [...arr, 3]; // [1, 2, 3]
16. What is the difference between map and forEach
•
map
: returns a new array•
forEach
: performs action but returns undefined17. What is the use of localStorage and sessionStorage
•
localStorage
: persists data even after browser is closed•
sessionStorage
: persists data only for session18. What is a prototype in JavaScript
Every object has a prototype — an object it inherits methods and properties from. Enables inheritance.
19. What is the difference between synchronous and asynchronous code
• Synchronous: executes line by line
• Asynchronous: executes independently, doesn’t block main thread
20. What are modules in JavaScript
Used to split code into reusable pieces
Example:
// file.js
export const greet = () => "Hello";
// main.js
import { greet} from './file.js';
👍 React for more Interview Resources #javascript #interview #coding #webdev #frontend
❤5👍1