ING Bank Client Interview Questions
const products = [
Key Concepts
1. Memory Allocation
When you create variables, objects, arrays, etc., JavaScript allocates memory for them.
2. Reachability
Garbage collectors use the concept of "reachability" to decide if an object is still needed.
Reachable = still usable = not garbage
-
Variables in scope
-
Objects referenced by reachable objects
-
Function parameters and closures
3. Unreachable Objects
If there’s no way to reach an object, it's considered "garbage" and will be collected.
๐ง Algorithms (behind the scenes)
✅ Most Common: Mark-and-Sweep
-
Mark all reachable objects starting from roots (like global variables).
-
Sweep through memory and delete anything not marked.
⚠️ Important Notes
-
GC is automatic, but not predictable (you can’t force it).
-
Memory leaks can still happen (e.g., if you keep references unintentionally).
๐ Example
๐ณ 1. Original DOM (Real DOM)
The actual document structure loaded in the browser.
-
๐ What: The real HTML document (
document,document.body, etc.) -
๐ข Slow to update — changes cause reflows and repaints
-
๐ Directly manipulated via JS (
getElementById,innerHTML, etc.)
๐ช 2. Virtual DOM
A lightweight in-memory copy of the Real DOM used by libraries like React.
-
๐ What: JavaScript representation of the DOM
-
⚡ Fast updates — diffs new vs old virtual DOM, applies only real changes
-
๐ง Improves performance by minimizing real DOM manipulation
๐งฑ 3. Shadow DOM
A browser feature for encapsulating part of the DOM inside a component.
-
๐ What: A scoped DOM subtree hidden from the main DOM
-
๐งผ Isolated styles & markup — no CSS bleeding in or out
-
๐ Great for Web Components
| Feature | Real DOM | Virtual DOM | Shadow DOM |
|---|---|---|---|
| Part of browser | ✅ Yes | ❌ No (JS Concept) | ✅ Yes |
| Speed | ๐ข Slower | ⚡ Faster | ๐ Fast (isolated) |
| Isolation | ❌ No | ❌ No | ✅ Yes |
| Used by | All web pages | React, Vue | Web Components |
| Updates | Manual/Direct | Diff & Patch | Scoped and safe |
Comments
Post a Comment