2015年4月6日 星期一

Javascript - Let description


1. What is it?

The let statement declares a block scope local variable, optionally initializing it to a value. and use in ECMA 5.

2. How to use it



if (x > y) {
  let gamma = 12.7 + y;
  i = gamma * x;
}


3. Compare

I: Local variable
Variables declared within a JavaScript function,
become LOCAL to the function.

Local variables have local scope: They can only be accessed within the function
// Example 



II: Global variable
A variable declared outside a function, becomes GLOBAL

// Example 
var pi = 3.14;
var person = "John Doe";
var answer = 'Yes I am!'




 REF
MSDN



沒有留言:

張貼留言