Safer Code With let and const
Learn where and when you should use let or const.
var
does not have block scope and, in the past, that led developers to use a JavaScript design pattern known as Immediately Invoked Function Expression (IIFE) or the Self-Executing Anonymous Function. This pattern was also used to hide variables and functions from outside visibility.
Immediately Invoked Function Expression (IIFE)
In this pattern, lines of code are wrapped inside an anonymous function that is immediately executed.
Why IIFE
For example, in the following code, the variable sqrt
, defined within the block, is
Get hands-on with 1400+ tech skills courses.