Lexical Scoping defines the scope of a variable according to the position of that variable declared in the source code. This refers to the variables defined between its curly brackets. Once we use the let keyword in the for-loop, it will create a new lexical scope in each iteration. This means that the previous value of j is copied from the previous scope to the new one.

4m read timeFrom ayeshasahar.hashnode.dev
Post cover image
Table of contents
What exactly is a Closure?Lexical ScopingJavaScript ClosuresClosures in a loopWhy learn Closures?

Sort: