Java Reference
In-Depth Information
<< 1
<< 2
<< 3
<< Error: "i is not defined"
Note: Using let for Block Scoping
The next version of ECMAScript supports block scoping if the let
keyword is used instead of var . This has already been implemented in
many modern browsers. Try the following example to see if it works in your
browser:
var list = [1,2,3];
for (let i = 0, max = list.length ; i < max ;
i++ ){
console.log(list[i]);
}
console.log(i); // i is not available outside
the for block
Initialization Code
An IIFE can be used to set up any initialization code that there'll be no need for again. Be-
cause the code is only run once, there's no need to create any reusable, named functions,
and all the variables will also be temporary. An IIFE will be invoked once and can set up
any variables, objects, and event handlers when the page loads. The following example
logs a welcome message to the console and then eliminates all the temporary variables that
are used in putting the message together:
(function() {
var name = "Bart"; // This might be obtained from a
cookie in
reality
var days =
["Sunday","Monday","Tuesday","Wednesday","Thursday",
"Friday","Saturday"];
Search WWH ::




Custom Search