Skip to content

Commit 6b05539

Browse files
Update README.md
1 parent 1b02260 commit 6b05539

1 file changed

Lines changed: 8 additions & 16 deletions

File tree

README.md

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3029,9 +3029,6 @@ for (let i = 0; i < 10; i++) {
30293029
}
30303030
```
30313031

3032-
**Real-World Use Case:**
3033-
In a Node.js REST API, `if/else` chains validate incoming request payloads (checking required fields, type constraints, and business rules) before passing control to the service layer — keeping the controller logic clean and the happy path unindented.
3034-
30353032
<div align="right">
30363033
<b><a href="#table-of-contents">↥ back to top</a></b>
30373034
</div>
@@ -3079,9 +3076,6 @@ if (value) {
30793076
}
30803077
```
30813078

3082-
**Real-World Use Case:**
3083-
In a React component rendering a dashboard widget, an `if...else if` ladder checks the API response status (`"loading"`, `"error"`, `"empty"`, `"success"`) and returns the appropriate JSX. Placing the `"loading"` state first ensures the spinner is shown instantly while data fetches, improving perceived performance.
3084-
30853079
<div align="right">
30863080
<b><a href="#table-of-contents">↥ back to top</a></b>
30873081
</div>
@@ -3155,9 +3149,6 @@ switch (x) {
31553149
}
31563150
```
31573151

3158-
**Real-World Use Case:**
3159-
In a Redux reducer, a `switch` on `action.type` is the canonical pattern. Each `case` maps to a specific action string (e.g., `"INCREMENT"`, `"DECREMENT"`, `"RESET"`), returning a new state object. This pattern is readable, scalable, and directly documented in the Redux style guide.
3160-
31613152
<div align="right">
31623153
<b><a href="#table-of-contents">↥ back to top</a></b>
31633154
</div>
@@ -3225,7 +3216,8 @@ for (const val of arr) {
32253216
}
32263217
```
32273218

3228-
**Real-World Use Case:**
3219+
**Real-World Use Case:**
3220+
32293221
In a Node.js data-processing pipeline, `for...of` with `await` (inside an `async` function) iterates over a paginated API result set sequentially — something `forEach` cannot do since it ignores returned Promises. `for...in` is used to dynamically enumerate config object keys when serializing environment-specific settings.
32303222

32313223
<div align="right">
@@ -3278,9 +3270,6 @@ while (true) {
32783270
console.log(counter); // 5
32793271
```
32803272

3281-
**Real-World Use Case:**
3282-
A `do...while` loop is ideal for a CLI tool (e.g., a Node.js interactive script using `readline`) where you always need to display a menu at least once and re-display it until the user selects "Exit". A `while` loop suits polling a queue (`while (queue.length > 0)`) in a job processor, since the queue might be empty on startup.
3283-
32843273
<div align="right">
32853274
<b><a href="#table-of-contents">↥ back to top</a></b>
32863275
</div>
@@ -3336,6 +3325,7 @@ outerLoop: for (let i = 0; i < 3; i++) {
33363325
```
33373326

33383327
**Real-World Use Case:**
3328+
33393329
In a search autocomplete engine, `break` short-circuits a loop over a large dataset once the desired number of suggestions is collected, preventing unnecessary iterations. `continue` is used in data-cleaning pipelines to skip `null` or malformed records without nesting the entire logic in an extra `if` block — keeping cyclomatic complexity low and the code easier to review.
33403330

33413331
<div align="right">
@@ -3392,6 +3382,7 @@ if (isLoggedIn) {
33923382
```
33933383

33943384
**Real-World Use Case:**
3385+
33953386
In React, the ternary operator is the standard pattern for conditional rendering within JSX since JSX is an expression context — `if` statements cannot appear inside `{}` interpolation. For example, rendering a loading spinner vs. a data table based on `isLoading` state is universally handled with a ternary.
33963387

33973388
<div align="right">
@@ -3443,6 +3434,7 @@ console.log(city); // "Unknown City"
34433434
```
34443435

34453436
**Real-World Use Case:**
3437+
34463438
When consuming third-party REST APIs or GraphQL responses, deeply nested fields may be absent depending on the query. Optional chaining eliminates dozens of guard clauses like `if (response && response.data && response.data.user)`. Nullish coalescing is critical when a user-configurable setting has `0` or `""` as a valid value — falling back with `||` would incorrectly override those legitimate settings.
34473439

34483440
<div align="right">
@@ -3511,6 +3503,7 @@ searchGrid: for (let i = 0; i < rows; i++) {
35113503
```
35123504

35133505
**Real-World Use Case:**
3506+
35143507
In a pathfinding algorithm (e.g., BFS/DFS on a 2D game map) or a seat-selection engine scanning rows and seats in a stadium booking system, a labeled `break` exits all nested loops the moment a valid seat is located — avoiding a boolean flag variable that would otherwise pollute the outer scope and add an extra condition to every loop header.
35153508

35163509
<div align="right">
@@ -3570,7 +3563,8 @@ if (isAuthenticated) {
35703563
}
35713564
```
35723565

3573-
**Real-World Use Case:**
3566+
**Real-World Use Case:**
3567+
35743568
In React, `&&` short-circuit is the idiomatic pattern for **conditional rendering**: `{isLoggedIn && <UserMenu />}` renders the component only when `isLoggedIn` is truthy, with no JSX `if` block needed. The `||` operator is universally used for **default parameter fallbacks** before optional chaining became standard. In Node.js middleware chains, `&&` guards ensure a dependency (e.g., a database connection) is available before proceeding to query logic.
35753569

35763570
<div align="right">
@@ -17286,8 +17280,6 @@ onTTFB(sendToAnalytics); // Time to First Byte — target < 800ms
1728617280
| Migrate to streaming SSR | High | Medium | Later |
1728717281
| WebAssembly for a single CPU-bound algorithm | Very High | Low | Probably never |
1728817282

17289-
**Real-World Use Case:**
17290-
1729117283
<div align="right">
1729217284
<b><a href="#table-of-contents">↥ back to top</a></b>
1729317285
</div>

0 commit comments

Comments
 (0)