Tip 3 | Isolate Information with Block Scoped Variables |
In this tip, youâll learn how let prevents scope conflict in for loops and other iterations.
At one point or another, every developer will make the mistake of capturing the wrong variable during a for loop. The traditional solution involves some pretty advanced JavaScript concepts. Fortunately, the let variable declaration makes this complex issue disappear.
Remember, when you use a block scoped variable declaration, youâre creating a variable thatâs only accessible in the block. A variable declared in an if block isnât available outside the curly braces. A variable declared inside a for loop isnât available outside the curly braces of the for loop. But that doesnât mean you ...
Get Simplifying JavaScript now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.