✅ Web development Interview Questions with Answers Part-3
21. What is the difference between var, let, and const?
var is function scoped and allows redeclaration. let is block scoped and allows reassignment. const is block scoped and does not allow reassignment. I avoid var in modern code. I use const by default and let only when reassignment is required.
22. What is hoisting in JavaScript?
Hoisting is JavaScript’s behavior of moving declarations to the top of the scope. Function declarations are fully hoisted. Variables declared with var are hoisted but initialized as undefined. let and const are hoisted but not accessible before declaration. Accessing them early throws an error.
23. What is a closure and where do you use it?
A closure is a function that remembers variables from its outer scope, even after the outer function has finished execution. I use closures in callbacks, event handlers, and data privacy. They are common in React hooks and async code.
24. What is event bubbling and event capturing?
Event bubbling moves from the target element up to the parent. Event capturing moves from the parent down to the target. By default, JavaScript uses bubbling. I use event delegation based on bubbling for performance.
25. What is the difference between == and ===?
== compares values after type conversion. === compares both value and type. I always use === to avoid unexpected bugs.
26. What is the difference between arrow functions and regular functions?
Arrow functions do not have their own this. They inherit this from the parent scope. Regular functions have their own this based on how they are called. I use arrow functions for callbacks and functional code. I use regular functions for object methods when needed.
27. What are call, apply, and bind used for?
They control the value of this. call invokes a function with arguments passed individually. apply invokes a function with arguments as an array. bind returns a new function with this permanently set. bind is useful for event handlers and callbacks.
28. What are promises and how does async await work?
Promises handle asynchronous operations. They represent pending, fulfilled, or rejected states. async await is syntax sugar over promises. It makes async code readable and sequential. I use try catch for error handling with async await.
29. What is the difference between setTimeout and setInterval?
setTimeout runs code once after a delay. setInterval runs code repeatedly at fixed intervals. I clear both using clearTimeout and clearInterval. I avoid setInterval when accuracy matters.
30. What is the difference between debounce and throttle?
Debounce delays execution until the event stops firing. Throttle limits execution to a fixed interval. I use debounce for search input. I use throttle for scroll and resize events.
Double Tap ♥️ For Part-4
Post #3425
4.25K
- ❤ 12
- 👍 2