Quick answer: JavaScript interviews for freshers mostly test seven areas: types and equality, scope and hoisting, functions and closures, arrays and objects, this and prototypes, promises and the event loop, and the DOM. Prepare a short spoken answer and one small code example for each. Then practise guess-the-output questions and be ready to explain a project you built.
These JavaScript fundamentals interview questions cover what freshers are usually asked before any React or Node.js question. They are grouped by topic. Say each answer aloud first, then read the extra detail.
All code here was run with Node.js. If a topic feels new, learn it in our JavaScript fundamentals tutorial before you memorise an answer.
Basics and types (Q1 to Q10)
Q1. What is JavaScript?
30-second answer: JavaScript is a programming language that makes web pages interactive. Browsers run it, and Node.js runs it on servers. It is dynamically typed, so a variable can hold any type, and the type can change later.
Q2. Is JavaScript the same as Java?
30-second answer: No. They are separate languages. Java is statically typed and usually compiled to bytecode for the JVM. JavaScript is dynamically typed and runs in a JavaScript engine. They share part of a name and some syntax, but code from one does not run in the other.
Q3. What are the data types in JavaScript?
30-second answer: There are seven primitive types: string, number, bigint, boolean, undefined, null and symbol. Everything else is an object, including arrays, functions and dates.
Q4. What is the difference between let, const and var?
30-second answer: let and const are block-scoped. var is function-scoped. You can reassign let and var, but not const. A const object can still have its contents changed.
Q5. What is the difference between == and ===?
30-second answer: == may convert types before comparing. === compares value and type with no conversion. Use === by default.
console.log(1 == "1"); // true
console.log(1 === "1"); // false
Q6. What is the difference between null and undefined?
30-second answer: undefined means no value has been set yet. null is a value you assign to say "empty on purpose".
Interview note:
typeof nullreturns"object". This is an old language bug kept for compatibility.
Q7. What is type coercion?
30-second answer: Coercion is automatic conversion from one type to another. "5" - 2 gives 3, because - needs numbers. "5" + 2 gives "52", because + joins when one side is a string.
Q8. What are falsy values?
30-second answer: Values treated as false in a condition: false, 0, -0, 0n, "", null, undefined and NaN. An empty array and an empty object are truthy.
Q9. What is NaN, and how do you check for it?
30-second answer: NaN means "not a number", such as the result of Number("abc"). It is not equal to itself, so use Number.isNaN(value).
console.log(NaN === NaN); // false
console.log(Number.isNaN(Number("x"))); // true
Q10. What is a template literal?
30-second answer: A string in backticks. It can hold values with ${} and can span several lines. Example: Hello ${name}.
Scope and functions (Q11 to Q20)
Q11. What is scope?
30-second answer: Scope is the part of the code where a variable can be used. JavaScript has global, module, function and block scope. Inner code can read outer variables, but outer code cannot read inner ones.
Q12. What is hoisting?
30-second answer: Declarations are processed before the code runs. A function declaration can be called above its line. A var exists early with the value undefined.
console.log(total); // undefined
var total = 10;
console.log(add(2, 3)); // 5
function add(a, b) { return a + b; }
Q13. What is the temporal dead zone?
30-second answer: It is the time between the start of a block and the line where a let or const is declared. Reading the variable in that time throws a ReferenceError.
Q14. What is the difference between a function declaration and a function expression?
30-second answer: A declaration, function f() {}, is hoisted with its body. An expression, const f = function () {}, is a value, so you can use it only after that line runs.
Q15. What is an arrow function?
30-second answer: It is a shorter function syntax. It has no this or arguments of its own and cannot be used with new. It suits callbacks well.
Q16. What is a closure?
30-second answer: A closure is a function that remembers variables from the place where it was created, even after the outer function has finished.
function counter() {
let n = 0;
return () => ++n;
}
const next = counter();
next();
console.log(next()); // 2
Closures keep data private.
Q17. What is a callback function?
30-second answer: A function passed to another function, to be called later. [1, 2].map((n) => n * 2) passes a callback to map.
Q18. What is a higher-order function?
30-second answer: A function that takes a function, returns a function, or both. map, filter and reduce are examples.
Q19. What is the difference between parameters and arguments?
30-second answer: Parameters are the names in the function definition. Arguments are the real values you pass in the call.
Q20. What are default and rest parameters?
30-second answer: A default is used when an argument is missing or undefined. A rest parameter collects the remaining arguments in an array.
const sum = (start = 0, ...nums) => nums.reduce((a, b) => a + b, start);
console.log(sum(undefined, 2, 3)); // 5
Arrays and objects (Q21 to Q30)
Q21. How is map different from forEach?
30-second answer: map returns a new array with the callback's results. forEach returns undefined and is used for side effects such as printing.
Q22. What do filter and find return?
30-second answer: filter returns an array of all matches, which may be empty. find returns the first match, or undefined.
Q23. How does reduce work?
30-second answer: It combines all items into one result. The callback gets the result so far and the current item. The second argument to reduce is the starting value.
console.log([10, 20, 30].reduce((sum, n) => sum + n, 0)); // 60
Q24. What is the difference between slice and splice?
30-second answer: slice returns a copied part and leaves the array alone. splice removes or inserts items in the original array.
const a = [1, 2, 3, 4];
console.log(a.slice(1, 3)); // [ 2, 3 ]
a.splice(1, 2);
console.log(a); // [ 1, 4 ]
Q25. What is destructuring?
30-second answer: It is syntax that takes values out of an array or object into variables, such as const { name, age } = user;.
Q26. What is the spread operator?
30-second answer: ... expands an array or object. Use it to copy or join, as in [...a, ...b]. The copy is shallow, so nested objects are still shared.
Q27. What is the difference between a shallow copy and a deep copy?
30-second answer: A shallow copy duplicates only the outer level. A deep copy duplicates nested data too. structuredClone(obj) makes a deep copy of most plain data, but it throws an error if the object contains a function.
Q28. What is optional chaining?
30-second answer: user?.address?.city returns undefined if a part before ?. is null or undefined, so it does not throw an error.
Q29. How is a Map different from an object?
30-second answer: A Map accepts keys of any type, keeps insertion order and has a size. Object keys are strings or symbols.
Q30. How do you remove duplicates from an array?
30-second answer: Put it in a Set, then spread it back into an array.
console.log([...new Set([1, 2, 2, 3])]); // [ 1, 2, 3 ]
For objects, this removes only repeated references. Two objects with the same contents are still different.
this, prototypes and classes (Q31 to Q36)
Q31. What is this in JavaScript?
30-second answer: In a normal function, this is decided by how the function is called. In user.show(), it is user. In a plain call, it is undefined in strict mode. An arrow function takes this from the code around it.
Q32. What do call, apply and bind do?
30-second answer: All three set this. call runs the function with separate arguments. apply runs it with an array of arguments. bind returns a new function to run later.
Q33. What is a prototype?
30-second answer: It is an object from which another object can inherit properties. If JavaScript cannot find a property on the object, it looks along the prototype chain.
const animal = { legs: 4 };
const dog = Object.create(animal);
console.log(dog.legs); // 4
console.log(Object.hasOwn(dog, "legs")); // false
Q34. Are JavaScript classes real classes?
30-second answer: They are cleaner syntax built mainly on prototypes. Methods live on the class's prototype and are shared by every object made from it. More in OOP and prototypes questions.
Q35. What do extends and super do?
30-second answer: extends creates a child class. super() calls the parent constructor, and it must run before the child constructor uses this.
Q36. What is strict mode?
30-second answer: "use strict" turns some silent errors into real ones, such as assigning to an undeclared variable. Modules and classes use it automatically.
Async JavaScript (Q37 to Q43)
Q37. Is JavaScript single-threaded?
30-second answer: Your JavaScript runs on one main thread, one piece at a time. The browser or Node.js handles timers and network work outside it. Workers can run code on other threads.
Q38. What is the event loop?
30-second answer: It moves waiting callbacks to the call stack when the stack is empty. Microtasks, such as promise callbacks, run before the next timer.
console.log("A");
setTimeout(() => console.log("B"), 0);
Promise.resolve().then(() => console.log("C"));
console.log("D");
A
D
C
B
Q39. What is a promise?
30-second answer: An object that represents a result that may arrive later. It is pending, then fulfilled or rejected. Once settled, its state does not change.
Q40. What do async and await do?
30-second answer: An async function always returns a promise. await pauses that function until a promise settles. Other code keeps running.
Q41. How do you handle errors in async code?
30-second answer: Use try...catch around await, or .catch() on a promise chain. With fetch, also check response.ok, because a 404 does not reject the promise.
Q42. What is the difference between Promise.all and Promise.allSettled?
30-second answer: Promise.all rejects as soon as one promise rejects. Promise.allSettled waits for all and reports each result.
Q43. What is callback hell?
30-second answer: Deeply nested callbacks that are hard to read and handle. Promises and async/await make the steps flat.
DOM and browser (Q44 to Q50)
Q44. What is the DOM?
30-second answer: The Document Object Model is a tree of objects built from your HTML. JavaScript can read and change it.
Q45. What is event bubbling?
30-second answer: After an event reaches its target, most events move up through the parent elements. event.stopPropagation() stops that movement.
Q46. What is event delegation?
30-second answer: You put one listener on a parent and use event.target to see which child was clicked. It also works for children added later.
Q47. What does preventDefault do?
30-second answer: It stops the browser's default action, such as a form submit reloading the page. It does not stop bubbling.
Q48. How do localStorage and sessionStorage differ?
30-second answer: Both store strings. localStorage stays after the browser closes. sessionStorage belongs to one tab and ends when that tab closes. Do not keep secrets in either.
Q49. What is the difference between textContent and innerHTML?
30-second answer: textContent treats its value as plain text. innerHTML reads it as HTML, so unsafe user input can run code on your page.
Interview note: The name for that attack is cross-site scripting, or XSS. Say that you use
textContentfor user input.
Q50. What is the difference between debounce and throttle?
30-second answer: Debounce waits until activity stops, which suits a search box. Throttle runs at most once in each time gap, which suits scrolling.
JavaScript fundamentals MCQ and viva questions
This short JavaScript fundamentals MCQ round also covers common JavaScript fundamentals viva questions.
typeof []returns: (a) array (b) object (c) list (d) undefined- Which is block-scoped? (a) var (b) let (c) both (d) neither
Boolean([])is: (a) true (b) false (c) null (d) an error- Which method changes the original array? (a) map (b) slice (c) sort (d) filter
- An async function returns: (a) an array (b) a callback (c) a promise (d) nothing
Answers: 1-b, 2-b, 3-a, 4-c, 5-c.
JavaScript fundamentals interview questions: one-week plan
This plan for JavaScript fundamentals interview questions for freshers needs about two hours a day.
| Day | Work |
|---|---|
| 1 | Q1 to Q10, spoken without notes |
| 2 | Q11 to Q20, and write a closure from memory |
| 3 | Q21 to Q30, and solve five array problems |
| 4 | Q31 to Q36, and predict ten this outputs |
| 5 | Q37 to Q43, and draw the event loop |
| 6 | Q44 to Q50, and build a small form |
| 7 | Mock interview: ten random questions |
On each day, write down the questions you could not answer. Start the next day with that list.
Use our cheat sheet for revision and the practice problems for coding rounds. Then build one of these JavaScript projects, because the next question is nearly always "What have you made?" The full stack developer course guide shows what to learn after that.
Pro tip: End an answer with proof: "I used event delegation in my to-do app so that new tasks worked too." One real example makes a definition easy to believe.
Frequently asked questions
How many JavaScript questions should a fresher prepare?
Fifty well understood questions are enough for the fundamentals. Understanding matters more than the count, because interviewers change the code slightly and ask what happens. Add ten to fifteen small coding problems to your preparation.
What are common JavaScript viva questions?
Viva examiners often ask for the data types, let versus const versus var, == versus ===, what the DOM is, what an event is, what a function is and how JavaScript differs from Java. Give a one-line definition and one example for each.
Do freshers need to know closures and promises?
Yes. Closures, promises and the event loop are among the most common JavaScript topics for freshers. You should be able to define each one, read a short example and predict its output.
Should I learn React before a JavaScript interview?
Learn JavaScript first. React uses functions, closures, array methods, destructuring and modules all the time, so weak fundamentals show quickly. Add React when the job listing asks for it.
How do I answer a JavaScript question I do not know?
Say what you do know, then reason aloud from a simple example. For an output question, go line by line and say what each variable holds. A clear thought process is better than a confident guess.
Want to practise these answers with a trainer? Book a free demo class for the Full Stack Web Development programme, where you learn by building projects you can explain in an interview.
