JavaScript Interview Preparation
Guide
Top Conceptual & Coding Questions
Covers Fresher to Mid-Level Interviews
PART 1: Top Conceptual Interview Questions
1. Core JavaScript Concepts
1. What is the difference between var, let, and const?
2. What is hoisting in JavaScript? Give an example.
3. Explain closures with a real-world example.
4. What is the difference between == and ===?
5. What are truthy and falsy values in JavaScript?
6. What is the difference between null and undefined?
7. What is the Temporal Dead Zone (TDZ)?
8. Explain global, function, and block scope.
2. Functions
9. What is the difference between a regular function and an arrow function?
10. What is a higher-order function? Give an example.
11. What is a callback function and why is it used?
12. What is the difference between call(), apply(), and bind()?
13. What is an IIFE (Immediately Invoked Function Expression)?
14. What is function currying? Write an example.
15. What is memoization and when should you use it?
3. Asynchronous JavaScript
16. What is the difference between synchronous and asynchronous code?
17. What are Promises? Explain .then(), .catch(), and .finally().
18. What is async/await and how does it work internally?
19. What is the event loop in JavaScript?
20. What is the difference between setTimeout and setInterval?
21. What is callback hell and how do you avoid it?
22. What is the difference between microtask queue and macrotask queue?
4. Arrays & Objects
23. What is the difference between map(), filter(), and reduce()?
24. What is the difference between shallow copy and deep copy?
25. Explain object and array destructuring.
26. What is the spread operator (...) and rest parameter?
27. How does [Link]() work?
28. What is the difference between for...in and for...of?
29. What are WeakMap and WeakSet?
5. Prototypes & OOP
30. What is prototypal inheritance in JavaScript?
31. What is the difference between __proto__ and prototype?
32. What is a class in JavaScript? How is it different from a constructor function?
33. What does the this keyword refer to in different contexts?
34. What does the new keyword do internally?
6. DOM & Events
35. What is event bubbling and event capturing?
36. What is event delegation and why is it useful?
37. What is the difference between addEventListener and onclick?
38. How do you prevent default behavior of an event?
39. What is the difference between innerHTML, innerText, and textContent?
7. ES6+ Modern Features
40. What are template literals?
41. What are JavaScript modules (import/export)?
42. What is optional chaining (?.) and nullish coalescing (??)?
43. What are generators and iterators?
44. What are Symbols in JavaScript?
45. What is the difference between [Link], [Link], and [Link]?
8. Performance & Miscellaneous
46. What is debouncing and throttling? When would you use each?
47. What is the difference between localStorage, sessionStorage, and cookies?
48. What is CORS and how does it work?
49. What is a pure function?
50. What is strict mode in JavaScript?
51. How does garbage collection work in JavaScript?
PART 2: Coding Interview Questions
1. String Problems
Q1. Reverse a String
function reverseString(str) {
return [Link]('').reverse().join('');
}
[Link](reverseString('hello')); // 'olleh'
Q2. Check if a String is a Palindrome
function isPalindrome(str) {
const clean = [Link]().replace(/[^a-z0-9]/g, '');
return clean === [Link]('').reverse().join('');
}
[Link](isPalindrome('racecar')); // true
Q3. Count Character Occurrences
function charCount(str) {
return [Link]('').reduce((acc, char) => {
acc[char] = (acc[char] || 0) + 1;
return acc;
}, {});
}
[Link](charCount('hello')); // {h:1, e:1, l:2, o:1}
Q4. Check if Two Strings are Anagrams
function isAnagram(str1, str2) {
const sort = s => [Link]().split('').sort().join('');
return sort(str1) === sort(str2);
}
[Link](isAnagram('listen', 'silent')); // true
2. Array Problems
Q5. Remove Duplicates from an Array
function removeDuplicates(arr) {
return [...new Set(arr)];
}
[Link](removeDuplicates([1, 2, 2, 3, 4, 4])); // [1, 2, 3, 4]
Q6. Flatten a Nested Array
function flattenArray(arr) {
return [Link]((acc, val) =>
[Link](val) ? [Link](flattenArray(val)) : [Link](val), []);
}
[Link](flattenArray([1, [2, [3, [4]]]])); // [1, 2, 3, 4]
Q7. Find the Second Largest Number
function secondLargest(arr) {
const unique = [...new Set(arr)].sort((a, b) => b - a);
return unique[1];
}
[Link](secondLargest([5, 3, 9, 1, 9])); // 5
Q8. Move All Zeros to the End
function moveZeros(arr) {
return [...[Link](x => x !== 0), ...[Link](x => x === 0)];
}
[Link](moveZeros([0, 1, 0, 3, 12])); // [1, 3, 12, 0, 0]
Q9. Find Missing Number in 1 to N
function findMissing(arr, n) {
const expected = (n * (n + 1)) / 2;
const actual = [Link]((sum, val) => sum + val, 0);
return expected - actual;
}
[Link](findMissing([1, 2, 4, 5], 5)); // 3
3. Number Problems
Q10. Check if a Number is Prime
function isPrime(n) {
if (n <= 1) return false;
for (let i = 2; i <= [Link](n); i++) {
if (n % i === 0) return false;
}
return true;
}
[Link](isPrime(17)); // true
Q11. Fibonacci Series
function fibonacci(n) {
const result = [0, 1];
for (let i = 2; i < n; i++) {
[Link](result[i - 1] + result[i - 2]);
}
return [Link](0, n);
}
[Link](fibonacci(8)); // [0,1,1,2,3,5,8,13]
Q12. Factorial of a Number
function factorial(n) {
if (n <= 1) return 1;
return n * factorial(n - 1);
}
[Link](factorial(5)); // 120
4. Functions & Logic
Q13. Implement your own map()
[Link] = function(callback) {
const result = [];
for (let i = 0; i < [Link]; i++) {
[Link](callback(this[i], i, this));
}
return result;
};
[Link]([1,2,3].myMap(x => x * 2)); // [2, 4, 6]
Q14. Implement Debounce
function debounce(fn, delay) {
let timer;
return function(...args) {
clearTimeout(timer);
timer = setTimeout(() => [Link](this, args), delay);
};
}
// Usage: const debouncedSearch = debounce(search, 300);
Q15. Implement Throttle
function throttle(fn, limit) {
let lastCall = 0;
return function(...args) {
const now = [Link]();
if (now - lastCall >= limit) {
lastCall = now;
[Link](this, args);
}
};
}
// Usage: const throttledScroll = throttle(onScroll, 200);
Q16. Curry a Function
function curry(fn) {
return function curried(...args) {
if ([Link] >= [Link]) {
return fn(...args);
}
return function(...moreArgs) {
return curried(...args, ...moreArgs);
};
};
}
const add = curry((a, b, c) => a + b + c);
[Link](add(1)(2)(3)); // 6
5. Object Problems
Q17. Deep Clone an Object
function deepClone(obj) {
if (obj === null || typeof obj !== 'object') return obj;
if ([Link](obj)) return [Link](deepClone);
return [Link](
[Link](obj).map(([k, v]) => [k, deepClone(v)])
);
}
const original = { a: 1, b: { c: 2 } };
const clone = deepClone(original);
Q18. Group Array of Objects by Property
function groupBy(arr, key) {
return [Link]((acc, obj) => {
const group = obj[key];
if (!acc[group]) acc[group] = [];
acc[group].push(obj);
return acc;
}, {});
}
const people = [{name:'Alice', dept:'HR'}, {name:'Bob', dept:'IT'}, {name:'Eve',
dept:'HR'}];
[Link](groupBy(people, 'dept'));
6. Tricky Output Questions (Very Common!)
These are extremely popular — the interviewer shows code and asks what the output will be.
Q19. var in a Loop with setTimeout
for (var i = 0; i < 3; i++) {
setTimeout(() => [Link](i), 1000);
}
// Output: 3 3 3 (NOT 0 1 2)
// Fix using let:
for (let i = 0; i < 3; i++) {
setTimeout(() => [Link](i), 1000);
}
// Output: 0 1 2
Q20. Closure Output
function outer() {
let count = 0;
return function() {
count++;
[Link](count);
};
}
const counter = outer();
counter(); // 1
counter(); // 2
counter(); // 3
Q21. Event Loop Order (Promise vs setTimeout)
[Link]('start');
setTimeout(() => [Link]('setTimeout'), 0);
[Link]().then(() => [Link]('promise'));
[Link]('end');
// Output:
// start
// end
// promise <-- microtask runs before macrotask
// setTimeout
Q22. Hoisting Output
[Link](x); // undefined (hoisted)
var x = 5;
[Link](y); // ReferenceError (TDZ)
let y = 10;
PART 3: Interview Tips
Tip 1: Always think out loud. Explain your approach before writing code.
Tip 2: Start with a brute force solution first, then optimize it.
Tip 3: Always handle edge cases — null, empty arrays, zero, negative numbers.
Tip 4: Know the time complexity (Big O) of your solution.
Tip 5: Practice on LeetCode, HackerRank, and JSFiddle regularly.
Tip 6: Review ES6+ features — modern JavaScript is expected in all interviews.
PART 4: Quick Reference — Common Methods
Method Description Returns
map() Transforms each element New array
filter() Keeps elements that pass test New array
reduce() Reduces array to single value Single value
find() Finds first matching element Element or undefined
some() Checks if any element passes Boolean
every() Checks if all elements pass Boolean
includes() Checks if value exists Boolean
flat() Flattens nested arrays New array
[Link]() Gets object keys Array of keys
[Link]() Gets object values Array of values
[Link]() Gets key-value pairs Array of pairs
[Link]() Converts object to JSON string String
[Link]() Converts JSON string to object Object
All the Best for Your Interview!
Prepare well, stay confident, and keep coding!