β
20 JavaScript Interview Questions1.
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 JavaScriptVariables and function declarations are moved to the top of their scope before execution.
Only declarations are hoisted, not initializations.
4.
What is a closureA 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-assigned
6.
What is event delegationUsing 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 JavaScriptHandle asynchronous operations.
States: pending, fulfilled, rejected
Example:
fetch(url)
.then(res => res.json())
.catch(err => console.error(err));
8.
What is async/awaitSyntactic 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 assigned
10.
What is the use of arrow functionsShorter syntax, no own
this binding
Example:
const add = (a, b) => a + b;
11.
What is the DOMDocument 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 context
13.
What is the use of setTimeout and setIntervalβ’
setTimeout: runs code once after delay
β’
setInterval: runs code repeatedly at intervals
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:
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 undefined
17.
What is the use of localStorage and sessionStorageβ’
localStorage: persists data even after browser is closed
β’
sessionStorage: persists data only for session
18.
What is a prototype in JavaScriptEvery 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 JavaScriptUsed 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