✅ Web development Interview Questions with Answers Part-4
31. What is prototypal inheritance in JavaScript?
JavaScript uses prototype-based inheritance. Objects inherit properties from other objects through the prototype chain. When a property is not found, JavaScript looks up the chain. This avoids duplication and improves memory usage.
32. How does the this keyword behave in different contexts?
In the global scope, this refers to the window or undefined in strict mode. In a function, it depends on how the function is called. In a method, this refers to the object. In arrow functions, this is inherited from the parent scope.
33. What is the difference between shallow copy and deep copy?
Shallow copy duplicates references for nested objects. Deep copy duplicates everything. Shallow copy is faster but risky for nested data. I use structuredClone or JSON methods based on the use case.
34. How does the JavaScript event loop work?
JavaScript is single-threaded. The event loop handles asynchronous tasks. The call stack executes synchronous code first. Async tasks go to task queues. The event loop pushes tasks back to the stack when it is empty.
35. What is the difference between microtasks and macrotasks?
Microtasks have higher priority. Promises use the microtask queue. setTimeout uses the macrotask queue. Microtasks run before the next render cycle.
36. What causes memory leaks in JavaScript and how do you prevent them?
Uncleared timers. Detached DOM nodes. Unused global variables. I remove event listeners and clear intervals. I monitor memory using browser dev tools.
37. What are JavaScript modules and bundlers?
Modules allow code to be split into reusable files. Bundlers combine modules into optimized bundles. They handle dependency graphs and asset loading. Common tools include Webpack and Vite.
38. What is tree shaking and why is it important?
Tree shaking removes unused code from bundles. It reduces file size. It improves load time and performance. It works best with ES modules.
39. What are polyfills and when do you need them?
Polyfills add missing features to older browsers. They replicate modern APIs. I include them only when browser support requires it.
40. What are the different web storage options available in browsers?
Local storage persists data without expiration. Session storage clears on tab close. Cookies store small data and are sent with requests. I avoid storing sensitive data in all of them.
Double Tap ♥️ For Part-5
Post #3427
3.77K
- ❤ 15
- 👍 2