TheDevSpace | Full-Stack Web Development Course
20 JavaScript Interview Questions
Next.js SaaS Boilerplate & Full-Stack Dev Course
www.thedevspace.io
Core JavaScript
1. What is the difference between var , let , and const ?
var : Function-scoped, hoisted, can be redeclared.
let : Block-scoped, not hoisted the same way, can't be
redeclared in the same scope.
const : Block-scoped, must be initialized, value cannot be
reassigned.
2. How does JavaScript handle asynchronous code?
Through callbacks, promises, and async/await.
The event loop and task queue ensure non-blocking behavior.
3. What are closures in JavaScript? Give an example.
A closure is a function that remembers the variables from its
lexical scope even when executed outside that scope.
1 function outer() {
2 let count = 0;
3 return function inner() {
4 return "#count;
5 }
6 }
7 const counter = outer();
8 counter(); "$ 1
9 counter(); "$ 2
thedevspace.io
TheDevSpace | Full-Stack Web Development Course
4. Explain the concept of hoisting in JavaScript.
Declarations ( var , function ) are moved to the top of their
scope during compilation.
let and const are hoisted but not initialized (temporal dead
zone).
5. What is the this keyword? How does it behave in different
contexts?
Refers to the object calling the function.
In global context: window (in browsers).
In strict mode: undefined .
In arrow functions: lexically bound (doesn’t change based on
caller).
6. What is the difference between !" and !!# in JavaScript?
"% : loose equality, allows type coercion.
""& : strict equality, checks type and value.
7. What are truthy and falsy values in JavaScript?
Falsy values: false , 0 , '' , null , undefined , NaN .
Everything else is truthy.
8. How does the event loop work in JavaScript?
Executes synchronous code first, then handles asynchronous
tasks via the call stack, callback queue, and microtask queue
(promises first, then other callbacks).
9. What are arrow functions, and how do they differ from regular
functions?
Shorter syntax.
Do not have their own this , arguments , super , or new.target .
Cannot be used as constructors.
thedevspace.io
TheDevSpace | Full-Stack Web Development Course
10. What is the difference between shallow copy and deep copy?
Shallow copy copies references to nested objects.
Deep copy duplicates all levels of the object.
1 "$ Shallow
2 const copy = {""(original};
3 "$ Deep
4 const deepCopy = JSON.parse(JSON.stringify(original));
Object-Oriented and Functional
Programming
11. How does prototypal inheritance work in JavaScript?
Objects inherit properties from their prototype chain via
"'proto"' or Object.create() .
Functions have a prototype object used for inheritance when using
new .
12. What are higher-order functions? Give an example.
Functions that take other functions as arguments or return them.
1 function multiplyBy(n) {
2 return function(x) {
3 return x * n;
4 };
5 }
6 const double = multiplyBy(2);
13. What is the difference between call, apply, and bind?
call : invokes a function with a given this and arguments.
apply : same as call , but args passed as an array.
thedevspace.io
TheDevSpace | Full-Stack Web Development Course
bind : returns a new function with this bound.
14. How do you implement private variables in JavaScript?
Using closures or # private fields in classes.
1 class Counter {
2 #count = 0;
3 increment() { this.#count"#; }
4 get value() { return this.#count; }
5 }
15. What are the advantages of functional programming patterns in
JavaScript?
Predictable, testable, less side-effect prone.
Encourages immutability and composability.
Browser and DOM
16. How does event delegation work in JavaScript?
Attaching a single event listener to a parent instead of each
child.
Uses event bubbling to catch events from children.
17. What is the difference between e.preventDefault() and
e.stopPropagation() ?
preventDefault() : stops the default browser action.
stopPropagation() : stops the event from bubbling up the DOM.
18. How do you debounce or throttle a function in JavaScript?
Debounce: delays execution until a pause in input.
Throttle: limits execution to once per time interval.
thedevspace.io
TheDevSpace | Full-Stack Web Development Course
1 function debounce(fn, delay) {
2 let timer;
3 return (""(args) ") {
4 clearTimeout(timer);
5 timer = setTimeout(() ") fn(""(args), delay);
6 };
7 }
ES6+ and Modern JS
19. What are destructuring and spread/rest operators in JavaScript?
Destructuring: extracting values from arrays/objects.
1 const [a, b] = [1, 2];
2 const {name} = {name: 'Eric'};
Spread ( ""( ): expands iterable values.
1 const arr = [""(arr1, ""(arr2];
Rest ( ""( ): collects remaining values.
1 function sum(""(args) {}
20. What are modules in JavaScript? How do import and export work?
Modules split code into reusable files.
Use export to expose parts of a module and import to bring them
into another.
1 "$ module.js
2 export function greet() {}
3
4 "$ main.js
5 import { greet } from './module.js';
thedevspace.io
TheDevSpace | Full-Stack Web Development Course
thedevspace.io