Engineering note · React Js
Labels: Names used to label loops and control flow
Labels in Node.js (and JavaScript) are used to name a statement, typically for controlling the flow of loops or conditional statements. Labels can be particularly useful for breaking out of or continuing a specific loop when you have nested loops.
By Farah Jokhio Published Updated
outerLoop: for (let i = 0; i < 3; i++) {
for (let j = 0; j < 3; j++) {
if (j === 1) {
break outerLoop; // Exits the outer loop when j equals 1
}
console.log(`i = ${i}, j = ${j}`);
}
}
Here outer for loop is given a Label.
Labels are used with break or continue to exit or skip specific loops. They are most commonly used in nested loops.Usage in break and continue:
Marks the outer loop.Label outerLoop:
Exits the outerLoop when j equals 1, skipping any further iterations of the outer loop.break outerLoop;:
More engineering notes
Using useMemo for Caching and Optimizing Performance
~~`useMemo`~~ is a React Hook that helps optimize performance by memoizing (caching) the result of a...
Custom Hook : Simplify Code with Reusable Logic
The custom hook in React allows to write data-fetching logic once and reuse it across multiple compo...