This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sample | |
var vita = 90; | |
if (vita >= 80) { | |
console.log('Vita 分數大於 80 分'); // 會印出 Vita 分數大於 80 分 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 基本 if 指令介紹 | |
if (條件式) { | |
條件式為 true 時執行此指令區塊 | |
} else { | |
條件式為 false 時執行此指令區塊 | |
} | |
// Sample | |
var vita = 90; | |
if (vita >= 80) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sample 1 | |
var value = 1; | |
console.log(typeof(value)); // 會得到資料型別為 number | |
// Sample 2 | |
var value = 'Taipei'; | |
console.log(typeof(value)); // 會得到資料型別為 string | |
// Sample 3 | |
var value = ['MOP', 'TRCK', 'PROLINK']; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sample 1 | |
var ary = ['MOP', 'TRCK', 'PROLINK']; | |
console.log(delete ary[0]); // 回傳 true | |
console.log(ary); // 得到 ary 為 [empty, "TRCK", "PROLINK"] | |
// Sample 2 | |
var obj = {x:1, y:2, z:3}; | |
console.log(delete obj.x); // 回傳 true | |
console.log(obj); // 得到 obj 為 {y:2, z:3} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sample 1 | |
var x = 1; | |
var y = 2; | |
console.log(x === 1 && y === 1); // 會得到 false | |
console.log(x === 1 || y === 1); // 會得到 true | |
// Sample 2 | |
var a = 'Taiwan' | |
var b = 'China' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sample 1 | |
var x = 40000; | |
console.log((x > 22000) ? '大學生薪水' : '高中生薪水' ); | |
// Sample 2 | |
var vita = 'boy'; | |
console.log((vita === 'boy') ? '男生' : '女生' ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// == 相等運算子範例 | |
console.log(1 == true) // 會得到 true | |
console.log('1' == 1) // 會得到 true | |
console.log('3.14E2' == 314) // 會得到 true | |
// === 嚴格相等運算子範例 | |
console.log(1 == true) // 會得到 false | |
console.log('1' == 1) // 會得到 false | |
console.log('3.14E2' == 314) // 會得到 false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 以下左右兩邊的意思是相同的 | |
x++ <==> x = x + 1; | |
x-- <==> x = x - 1; | |
// Example 1 | |
var x = 10; | |
var y = x++; | |
console.log(x) // 會得到 11 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 由於 10 跟 1 都是數值,所以這就單純變成數值的加總 | |
console.log(20 + 1) // 會得到 21 | |
// 這裡要注意的是 10 為字串,1 為數值; 字串與任何資料型別相加,最終都會變成字串 | |
console.log('20' + 5) // 會得到 205 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var x; | |
var arrayBook = ["Ruby","Rails","React"]; | |
var objSample = {x:10, y:20} | |
console.log(x); // 會得到 undefined (有宣告 x 變數,可是沒有帶參數給 x) | |
console.log(arrayBook[3]); // 會得到 undefined (這個陣列長度只到 2,沒有到 3) | |
console.log(objSample.z); // 會得到 undefined (屬性 z 不存在) |