js語法
宣告
var
宣告一個可隨意更改其內容的變數
let
宣告一個可隨意更改其內容的區塊區域變數
const
宣告一個只可讀取的不可變常數
window.thinggggggggg
全域變數
thing=['thing1','thing2']
陣列
wtf = { wtf1: 'lol',wtf1: 'lol' };
物件字面值 Object literals
範例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| var a=1; console.log(a);
let x=1; console.log(x);
var window.z=1; console.log(window.z);
var lol = ['lol1', , 'lol2']; console.log(lol[0]);
var wtf = { wtf1: 'lol', wtf2: function('lol'), wtf3: lol }; console.log(lol.wtf1);
|
if else
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| if (x===y){ yes(); } else{ no(); }
if (x===y) { yes(); } else if (x===z) { yessss(); } else if (x===0) { yesssssssss(); } else { no(); }
|
switch
1 2 3 4 5 6 7 8 9 10 11 12 13
| switch (input) { case "1": console.log("1"); break; case "2": console.log("2"); break; case "3": console.log("3"); break; default: console.log("0"); }
|
try
1 2 3 4 5 6 7 8 9
| try { if(0=0); } catch (e) { logMyErrors(e); } finally { console.log("yeeeeee"); }
|
for
1 2 3
| for (var i = 0; i < 10; i++) { console.log(i); }
|
for in
1 2 3 4
| var object = [1, 2, 3]; for (input in object) { console.log(input) }
|
for of
1 2 3 4
| var object = [1, 2, 3]; for (input of object) { console.log(input) }
|
do while
1 2 3 4 5
| var i=0; do { i += 1; console.log(i); } while (i < 2);
|
while
1 2 3 4 5 6 7
| while (true) { console.log("AAA"); }
while (var n < 3) { n++; }
|
迴圈例外處理
brake
終止迴圈
confinue
跳回迴圈判斷
function
1 2 3
| function lol(fuckthing){ return fuckthing; }
|