Top 50 JavaScript Interview Questions for Freshers
1. What is JavaScript?
Answer: JavaScript is a scripting language used to create dynamic and interactive web pages.
2. What are the features of JavaScript?
Answer:
Lightweight
Interpreted
Dynamic Typing
Event-Driven
Object-Oriented
3. What is the difference between Java and JavaScript?
Java JavaScript
Compiled Interpreted
OOP Language Scripting Language
Runs on JVM Runs in Browser/[Link]
4. What are variables in JavaScript?
Answer: Variables store data values.
let name = "Neha";
5. Difference between var, let, and const?
var let const
Function Scope Block Scope Block Scope
Re-declaration Allowed Not Allowed Not Allowed
Reassignment Allowed Allowed Not Allowed
6. What are Data Types in JavaScript?
Primitive Types:
String
Number
Boolean
Undefined
Null
Symbol
BigInt
7. What is typeof operator?
typeof "Hello"; // string
typeof 10; // number
8. Difference between null and undefined?
null undefined
Intentional empty value Variable not assigned
Object type Undefined type
9. What is Hoisting?
Answer: JavaScript moves variable and function declarations to the top of their scope before
execution.
[Link](a);
var a = 10;
10. What is Scope?
Answer: Scope determines where variables can be accessed.
Types:
Global Scope
Function Scope
Block Scope
11. What is a Function?
function greet() {
[Link]("Hello");
12. What is a Function Expression?
const greet = function() {
[Link]("Hello");
};
13. What is an Arrow Function?
const greet = () => {
[Link]("Hello");
};
14. Difference between Arrow Function and Normal Function?
Answer: Arrow functions do not have their own this.
15. What is a Callback Function?
function greet(name, callback){
callback();
A function passed as an argument to another function.
16. What is Closure?
Answer: A closure allows a function to access variables from its outer scope even after the outer
function has finished executing.
function outer(){
let count = 0;
return function(){
count++;
return count;
}
17. What is an IIFE?
(function(){
[Link]("Executed");
})();
Immediately Invoked Function Expression.
18. What is this keyword?
Answer: Refers to the current object executing the function.
19. Difference between == and ===?
== ===
Value Comparison Value + Type Comparison
Type Conversion No Type Conversion
5 == "5" // true
5 === "5" // false
20. What are Objects?
const user = {
name: "Neha",
age: 23
};
21. What is an Array?
const fruits = ["Apple", "Mango"];
22. Difference between Array and Object?
Array Object
Indexed Key-Value Pair
Array Object
[] {}
23. What is Destructuring?
const {name, age} = user;
24. What is Spread Operator?
const arr2 = [...arr1];
25. What is Rest Operator?
function sum(...numbers){
26. What is Event Bubbling?
Answer: Event propagates from child element to parent.
27. What is Event Capturing?
Answer: Event propagates from parent to child.
28. What is DOM?
Answer: DOM (Document Object Model) represents HTML elements as objects.
29. How to select an element?
[Link]("demo");
[Link](".box");
30. What is an Event Listener?
[Link]("click", handler);
31. What is JSON?
Answer: JavaScript Object Notation used for data exchange.
"name":"Neha"
32. What is [Link]()?
[Link](jsonData);
Converts JSON string to object.
33. What is [Link]()?
[Link](object);
Converts object to JSON string.
34. What is Promise?
Answer: Represents an asynchronous operation.
States:
Pending
Fulfilled
Rejected
35. What is async and await?
async function getData(){
const res = await fetch(url);
Used to handle asynchronous operations.
36. What is Fetch API?
fetch(url)
.then(res => [Link]());
Used to call APIs.
37. Difference between Synchronous and Asynchronous?
Synchronous Asynchronous
Executes line by line Executes independently
Blocking Non-blocking
38. What is a Promise Chain?
fetch(url)
.then()
.then()
.catch();
39. What is Error Handling?
try {
catch(error){
40. What is Local Storage?
Answer: Stores data permanently in browser.
[Link]("name","Neha");
41. What is Session Storage?
Answer: Stores data until browser tab closes.
42. Difference between Local Storage and Session Storage?
Local Storage Session Storage
Permanent Temporary
Larger Lifetime Tab Lifetime
43. What is ES6?
Answer: ECMAScript 2015 version introducing modern JavaScript features.
44. ES6 Features?
let
const
Arrow Functions
Classes
Template Literals
Destructuring
Spread Operator
45. What are Template Literals?
let name = "Neha";
[Link](`Hello ${name}`);
46. What are Classes?
class Person {
47. What is Inheritance?
class Student extends Person {
48. What is a Higher-Order Function?
Answer: Function that accepts another function as argument or returns a function.
Examples:
map()
filter()
reduce()
49. What is map()?
[Link](num => num * 2);
Returns a new array.
50. Difference between map() and forEach()?
map() forEach()
Returns New Array Returns Undefined
Used for Transformation Used for Iteration
Yes. If you're preparing seriously for a JavaScript Fresher Interview, these important questions are
also commonly asked and were not in the original 50.
Additional Important JavaScript Interview Questions (51–75)
51. What is the difference between slice() and splice()?
slice() splice()
Does not modify original array Modifies original array
Returns selected elements Adds/Removes elements
let arr = [1,2,3,4];
[Link](1,3); // [2,3]
52. What is the difference between call(), apply(), and bind()?
Method Arguments
call() Passed individually
apply() Passed as array
bind() Returns new function
53. What is a Higher Order Function?
Answer: A function that takes another function as an argument or returns a function.
Examples:
map()
filter()
reduce()
54. What is filter()?
const nums = [1,2,3,4];
const even = [Link](n => n % 2 === 0);
Returns elements matching a condition.
55. What is reduce()?
const sum = [1,2,3].reduce((a,b)=>a+b,0);
Reduces array to a single value.
56. Difference between map(), filter(), and reduce()?
Method Purpose
map() Transform data
filter() Filter data
reduce() Produce single value
57. What is the Event Loop?
Answer:
The Event Loop allows JavaScript to perform non-blocking asynchronous operations even though
JavaScript is single-threaded.
58. What is Single Threaded JavaScript?
Answer:
JavaScript executes one task at a time using a single call stack.
59. What is the Call Stack?
Answer:
A data structure that keeps track of function execution.
60. What is Callback Hell?
getUser(function(){
getOrders(function(){
getPayment(function(){
});
});
});
Too many nested callbacks making code hard to read.
61. How do Promises solve Callback Hell?
Answer:
Promises provide cleaner asynchronous code using .then() and .catch().
62. What is the difference between null, undefined, and NaN?
Value Meaning
null Empty value
undefined Not assigned
NaN Not a Number
63. What is setTimeout()?
setTimeout(() => {
[Link]("Hello");
}, 1000);
Executes code after a delay.
64. What is setInterval()?
setInterval(() => {
[Link]("Running");
}, 1000);
Executes repeatedly after fixed intervals.
65. Difference between setTimeout() and setInterval()?
setTimeout setInterval
Runs once Runs repeatedly
66. What is a Deep Copy and Shallow Copy?
Shallow Copy
const copy = {...obj};
Deep Copy
const copy = structuredClone(obj);
67. What is Object Destructuring?
const person = {
name:"Neha",
age:23
};
const {name, age} = person;
68. What is Array Destructuring?
const [a,b] = [10,20];
69. What is Optional Chaining?
user?.address?.city
Prevents errors if a property doesn't exist.
70. What is Nullish Coalescing (??)?
let name = null;
[Link](name ?? "Guest");
Returns default value only for null or undefined.
71. Difference between || and ???
0 || 10 // 10
0 ?? 10 // 0
?? checks only null and undefined.
72. What is Currying?
function add(a){
return function(b){
return a+b;
Converts a function with multiple arguments into nested functions.
73. What is Memoization?
Answer:
Caching function results to improve performance.
74. What are Generator Functions?
function* numbers(){
yield 1;
yield 2;
Generate values one at a time.
75. What is Debouncing?
Answer:
Limits function execution until user stops triggering events.
Example: Search Box API Calls.