Johannes Baum
Nov 13, 2021

Hey Lërnër,

the while loop is part of my explanation why the for loop using let behaves the way it does.

There are many people (including me) that are surprised when they find out that the let of the for loop behaves like it is declared within the block of the for loop and not in the same block that the whole for loop belongs to.

If that is already clear to you, you can just ignore that part.

One additional remark is that the examples in the article also work if they are not in the global scope. So it has nothing to do with i being in the global scope. setTimeout captures the value of it in a closure.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Johannes Baum
Johannes Baum

Written by Johannes Baum

Creator of GridEngine (https://github.com/Annoraaq/grid-engine) 👾 Software Engineer 🚀 JavaScript/TypeScript

Responses (1)

Write a response