Johannes Baum
1 min readNov 14, 2021

Hey,

You are correct, when you say that the while loop is not equivalent to the for loop using let. My intent was not to show a while loop equivalent to the for loop but instead the while loop is equivalent to what many people expect the for loop to behave like.

Because a while loop is more explicit in it's behavior than a for loop, I picked it to point out a common misconception about for loops using let.

But I should consider rephrasing it if it leads to confusion.

Regarding the transpilation there is a misunderstanding. It does not transpile the while loop but the for loop instead. The point of showing the transpilation is to show how the for loop using the let really behaves.

With my two examples (while loop and transpilation) I tried to show more explicit versions of the for loops.

You can also think of it in this way:

while loop: more explicit version of a for loop using var

transpiled code: more explicit version of a for loop using let.

To wrap it up, the main point of my article is to create awareness about the differences of using let or var in a for loop and try to show more explicit versions to support understanding how they work.

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

Hello,
Fully understood and now I get the point.
As you said I totally misunderstood the transpilation, I thought you referred to the "while" loop instead (I also tried to transpile myself the "while" loop, but I'm too lazy and I tried it with the…

--