PageRenderTime 114ms CodeModel.GetById 54ms app.highlight 6ms RepoModel.GetById 53ms app.codeStats 0ms

/js/lib/Socket.IO-node/support/expresso/deps/jscoverage/tests/javascript/javascript-let.js

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
JavaScript | 79 lines | 53 code | 18 blank | 8 comment | 6 complexity | fcc4e1210965db28e9bb272ec308c862 MD5 | raw file
 1// https://developer.mozilla.org/en/New_in_JavaScript_1.7
 2
 3// let statement
 4
 5let (x = x+10, y = 12) {
 6  print(x+y + "\n");
 7}
 8
 9// let expressions
10
11print( let(x = x + 10, y = 12) x+y  + "<br>\n");
12
13// let definitions
14
15if (x > y) {
16  let gamma = 12.7 + y;
17  i = gamma * x;
18}
19
20var list = document.getElementById("list");
21
22for (var i = 1; i <= 5; i++) {
23  var item = document.createElement("LI");
24  item.appendChild(document.createTextNode("Item " + i));
25
26  let j = i;
27  item.onclick = function (ev) {
28    alert("Item " + j + " is clicked.");
29  };
30  list.appendChild(item);
31}
32
33function varTest() {
34  var x = 31;
35  if (true) {
36    var x = 71;  // same variable!
37    alert(x);  // 71
38  }
39  alert(x);  // 71
40}
41
42function letTest() {
43  let x = 31;
44  if (true) {
45    let x = 71;  // different variable
46    alert(x);  // 71
47  }
48  alert(x);  // 31
49}
50
51function letTests() {
52  let x = 10;
53
54  // let-statement
55  let (x = x + 20) {
56    alert(x);  // 30
57  }
58
59  // let-expression
60  alert(let (x = x + 20) x);  // 30
61
62  // let-definition
63  {
64    let x = x + 20;  // x here evaluates to undefined
65    alert(x);  // undefined + 20 ==> NaN
66  }
67}
68
69var x = 'global';
70let x = 42;
71document.write(this.x + "<br>\n");
72
73// let-scoped variables in for loops
74var i=0;
75for ( let i=i ; i < 10 ; i++ )
76  document.write(i + "<br>\n");
77
78for ( let [name,value] in obj )
79  document.write("Name: " + name + ", Value: " + value + "<br>\n");