JavaScript | Tricky Output | SCOPE | IIFE

Answer

The following code will write the value 10 times.

What if I want values from 0-9 in the console?

There are different ways to achieve this.

By using IIFE

  • IIFE is Immediately Invoked Function Expressions.
  • By using IIFE’s we can also scope the value of the variable i to print the current index, instead of printing the final value as 10.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store