This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| **Concept** | **Details** | | |
|-------------------|------------------------------------------------------------------------------| | |
| **Promise State** | `pending`, `fulfilled`, `rejected` | | |
| **Microtask** | `.then`, `await`, `queueMicrotask()` | | |
| **Task** | `setTimeout`, `setInterval`, `fetch` | | |
| **Event Loop** | Runs call stack β microtasks β tasks | | |
| **async/await** | Syntactic sugar for Promises | | |
| **Error Handling**| Use `.catch()` or `try/catch` | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## JavaScript `this` Binding β At a Glance | |
| How You Call It | What `this` Refers To | | |
|-------------------------------------|----------------------------------| | |
| `regularFunction()` | `global` / `undefined` | | |
| `obj.method()` | `obj` | | |
| `arrowFunction()` | Inherited from lexical scope | | |
| `method.call(obj)` / `apply(obj)` | `obj` | | |
| `method.bind(obj)` | `obj` (returned function bound) | | |
| `setTimeout(function)` | `global` / `undefined` | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Syntax | What `this` refers to | | |
|-----------------------------|---------------------------------| | |
| Regular function | `undefined` (strict) / `window` | | |
| Object method | The object | | |
| Arrow function | Lexical surrounding scope | | |
| `call(obj)` / `apply(obj)` | `obj` | | |
| `bind(obj)` | `obj` (returns new function) | | |
| `setTimeout` (regular fn) | `undefined` / `window` | | |
| `setTimeout` (arrow fn) | Inherits from outer context | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Concept | Key Idea | | |
|--------------------------|--------------------------------------------------------------------------| | |
| Scope | Controls visibility of variables | | |
| Lexical Scope | Inner functions access variables from parent scopes | | |
| Hoisting | Declarations are moved to top before execution | | |
| TDZ (Temporal Dead Zone) | `let`/`const` exist but arenβt usable until initialized | | |
| Shadowing | Inner scope overrides variables with same name | | |
| Module Scope | JS Modules have isolated scope; vars aren't global unless exported | | |
| Call Stack | JS engine's way to manage function calls using LIFO | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Scope Type | Description | | |
|--------------------|-----------------------------------------------------------------------------| | |
| **Global Scope** | Accessible everywhere (outside any function or block) | | |
| **Function Scope** | `var` declarations inside a function are limited to it | | |
| **Block Scope** | `let` and `const` inside `{}` blocks are accessible only inside the block | | |
| **Lexical Scope** | Inner functions access outer variables from where they were defined | | |
| **Module Scope** | In ES Modules, variables are scoped to that file unless exported | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Feature | Function Declaration | Function Expression | Arrow Function | | |
|--------------------------------|-----------------------|----------------------|---------------------------| | |
| **Named** | Yes | Optional | Optional | | |
| **Hoisted** | Yes | No | No | | |
| **Lexical `this`** | No | No | Yes | | |
| **Can be used as constructor** | Yes | Yes | No | | |
| **Can be anonymous** | No | Yes | Yes | | |
| **Common Use** | General purpose | Callbacks | One-liners, Array methods | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Concept | Key Insight | | |
|---------------------------------|------------------------------------------------------------------------------| | |
| **Closure** | Inner functions keep reference to outer variables | | |
| **Callback** | A function passed to another function | | |
| **HOF (Higher-Order Function)** | A function that takes or returns another function | | |
| **Execution Context** | Each function call creates a new isolated scope | | |
| **Microtask vs Task Queue** | Promises (microtasks) are prioritized and run before setTimeout (task queue) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ββββββββββββββββββββββββββ | |
β JavaScript Code β | |
ββββββββββββββββββββββββββ | |
β | |
βΌ | |
ββββββββββββββ | |
β Call Stack β ββββββββββββββββββββββββββββββ | |
ββββββββββββββ β | |
β β | |
βΌ β |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## JavaScript Memory: Stack vs Heap | |
| **Stack** | **Heap** | | |
|----------------------------------|---------------------------------------------------| | |
| Fast, simple memory storage | Large, dynamic memory | | |
| Holds **primitive** values | Holds **reference** values (objects, arrays) | | |
| Copy by **value** | Variables store **memory addresses (references)** | | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## JavaScript Key Concepts β Day 1 Summary | |
| Term | Meaning | | |
|-----------------|---------------------------------------------------------| | |
| `var` | Function scoped, hoisted with `undefined` | | |
| `let` / `const` | Block scoped, exist in Temporal Dead Zone (TDZ) | | |
| Primitives | Copied by value (stored in the stack) | | |
| References | Copied by reference (stored in the heap) | | |
| Scope Chain | Functions access variables from outer scopes | | |
| Closure | Functions remember outer variables even after execution | |
NewerOlder