JavaScript Interview Questions
1. What is JavaScript?
JavaScript is a high-level, interpreted, single-threaded programming language used to build
interactive web applications. It runs in browsers and also on servers via [Link].
2. What are primitive data types?
string, number, boolean, null, undefined, bigint, symbol.
They are immutable and stored by value.
3. Difference between let, const, and var?
var: function-scoped, hoisted, can redeclare
let: block-scoped, no redeclare
const: block-scoped, cannot reassign
4. What is hoisting?
JavaScript moves variable and function declarations to the top of their scope during
compilation. var is initialized as undefined, let/const are in TDZ.
5. What is the difference between == and ===?
==: loose equality (type coercion)
===: strict equality (no coercion)
6. What is undefined vs null?
undefined: variable declared but not assigned
null: intentional absence of value
7. What is a function?
A reusable block of code that performs a task. Functions are first-class citizens in JS.
8. What are arrow functions?
Shorter syntax functions that don’t have their own this, arguments, or prototype.
9. What is this keyword?
Refers to the execution context object. Value depends on how the function is called.
10. What is an object?
A collection of key-value pairs used to store structured data.
11. What is an array?
An ordered collection of values, indexed numerically starting from 0.
12. What is NaN?
"Not-a-Number"—represents invalid numeric operations.
13. What is type coercion?
Automatic conversion of one data type to another (e.g., "5" + 1 → "51").
14. What is a template literal?
String syntax using backticks ` ` allowing interpolation: ${value}.
15. What is strict mode?
"use strict" enables stricter parsing, preventing common mistakes.
16. What is closure?
A function that remembers variables from its lexical scope even after the outer function has
executed.
17. What is lexical scope?
Scope determined by where variables/functions are written in code.
18. What is the event loop?
Handles asynchronous operations by moving tasks from callback queue to call stack.
19. What is a callback function?
A function passed as an argument and executed later.
20. What is a promise?
An object representing eventual completion or failure of an async operation (pending, fulfilled,
rejected).
21. What is async/await?
Syntax built on promises to write async code like synchronous code.
22. What is DOM?
Document Object Model—represents HTML as a tree structure for manipulation.
23. Difference between map and forEach?
map: returns new array
forEach: no return
24. What is destructuring?
Extract values from arrays/objects into variables.
25. What is spread operator (...)?
Expands elements (arrays/objects) into individual values.
26. What is rest operator?
Collects multiple elements into an array.
27. What is event delegation?
Attaching event listener to parent to handle child events via bubbling.
28. What is debouncing?
Delays function execution until user stops triggering event.
29. What is throttling?
Limits function execution to once per interval.
30. What is shallow vs deep copy?
Shallow: references nested objects
Deep: fully independent copy
31. What is bind, call, apply?
Used to control this:
call: args individually
apply: args array
bind: returns new function
32. What is prototype?
Object from which other objects inherit properties.
33. What is prototype chain?
Mechanism for property lookup through linked objects.
34. What is setTimeout?
Executes function after delay (async).
35. What is JSON?
Data format for storing and transferring data ([Link], [Link]).
36. What is execution context?
Environment where JS code runs (global + function contexts).
37. What is call stack?
Tracks function execution order (LIFO).
38. What are microtasks vs macrotasks?
Microtasks: promises
Macrotasks: setTimeout
39. What is currying?
Transforming function with multiple args into sequence of single-arg functions.
40. What is memoization?
Caching function results to improve performance.
41. What is event bubbling?
Event propagates from child → parent.
42. What is event capturing?
Event flows from parent → child.
43. What is [Link]()?
Prevents modification of object properties.
44. What is [Link]()?
Allows modification but not addition/removal of properties.
45. What are modules in JS?
Reusable code blocks using import/export.
46. What is tree shaking?
Removing unused code during bundling.
47. What is IIFE?
Immediately Invoked Function Expression—runs immediately after definition.
48. What is garbage collection?
Automatic memory management by removing unused objects.
49. What is Web Storage?
localStorage (persistent) and sessionStorage (session-based).
50. What is CORS?
Cross-Origin Resource Sharing—controls resource access across domains.