⚡ JavaScript Interview Questions with Answers
Q1. What is JavaScript?
👉 JavaScript is a programming language used to add interactivity to web pages (clicks, forms, dynamic updates).
Q2. Difference between let, const, and var?
- var → function scoped (old, avoid)
- let → block scoped (can change value)
- const → block scoped (cannot reassign)
💡 Example:
let a = 10;
a = 20; // allowed
const b = 10;
// b = 20 ❌ error
Q3. What is the DOM?
👉 DOM = Document Object Model
It allows JavaScript to access and modify HTML elements
Q4. What is an event in JavaScript?
👉 Any user action:
- click
- input
- submit
Q5. What is a function?
👉 A reusable block of code
function greet() {
console.log("Hello");
}
Q6. What is a closure?
👉 A function that remembers variables from its outer scope
function outer() {
let count = 0;
return function inner() {
count++;
console.log(count);
};
}
Q7. What is hoisting?
👉 Variables & functions are moved to top of scope during execution
💡 Only declaration is hoisted, not value
Q8. Difference between == and ===?
- == → compares value (loose)
- === → compares value + type (strict)
5 == "5" // true
5 === "5" // false
Q9. What is an arrow function?
👉 Short syntax for functions
const add = (a, b) => a + b;
Q10. What is an array?
👉 Collection of values
let arr = [1, 2, 3];
Q11. What is a Promise?
👉 Represents a future value (async operation)
States:
- Pending
- Resolved
- Rejected
Q12. What is async/await?
👉 Cleaner way to handle promises
async function getData() {
let res = await fetch("url");
}
Q13. What is the Event Loop?
👉 Handles asynchronous operations in JavaScript
💡 Ensures non-blocking execution
Q14. What is callback function?
👉 Function passed as argument
function greet(name, callback) {
callback(name);
}
Q15. What is debouncing?
👉 Limits function execution frequency
💡 Used in:
- Search bars
- Resize events
🔥 Coding Question
Q Reverse a String
function reverse(str) {
return str.split('').reverse().join('');
}
💡 Pro Tips (From Interview POV)
Focus on:
- Closures
- Promises + Async/Await
- DOM
- Event Loop
Always give real-life examples
🎯 Final Advice
👉 Don’t just read → code every question
👉 Practice on:
- LeetCode
- HackerRank
Double Tap ❤️ For More
Post #3681
4.22K
- ❤ 19