[intro]
Nested Loops
Nested loops is what we call when we essentially have a loop running within another loop. For example:
let text = "";
for (let i = 0; i < 3; i++) {
text += i + "<br>";
for (let j = 10; j < 13; j++) {
text += j + "<br>";
}
}
/* ----- Result: -----
0
10
11
12
1
10
11
12
2
10
11
12
*/
Code Explanation:
This will start with our text variable containing 0, and will essentially go through the loop 3 times, until we reach i = 2 (which is < 3).
Don’t worry about the "<br>" tag, it’s just there for our code to return to the next line after every iteration.
Every time the i gets incremented, the j will go through a loop 3 times starting from 10 until it reaches 12, every time increasing the value of the current i in the process.
Nested Arrays:
Nestecd Objects:
JavaScript Scope:
In JavaScript, scope determines the accessibility (visibility) of variables, and which has 3 types: 1- **Block scope:**0 2- Function scope: 3- Global scope: