Skip to content

Commit 97d2b42

Browse files
committed
examples for let and constant
1 parent 1d24255 commit 97d2b42

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

constant.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* constant is a single assignmet variable.
3+
*/
4+
5+
function foo(){
6+
const i = 1;
7+
8+
var bar = i; // 1
9+
var i = 2; // error
10+
}

let.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* let desclares a block scope local variable. let has been in Firefox for a
3+
* long time and is now a part of ES6.
4+
* IMPORTANT: If outside any block, let is scoped globally else will be scoped
5+
* to nearest enclosing block.
6+
*/
7+
8+
function foo(){
9+
for(let i = 0; i< 10; i++){
10+
// i is visible
11+
}
12+
// i is not visible
13+
}

0 commit comments

Comments
 (0)