let a = true alert(a) a = String(value) // 现在是字符串形式的true
alert("6" / "2") // string会转换成number类型进行转换 Number("6") // 6 Number("你好") // NaN
Boolean(1) // true Boolean(0) // false Boolean("abc") // true Boolean("") // false
let a = 1; a = -a
let a = 1 let b = 2 alert(a + b)
+true // 1 +"" // 0 +undefined // NaN
let a = 1 + 1
let a, b, c; a = b = c = 1
let a = 2 a += a a *= a a /= a a -= a
let a = 2 let b = a++ console.log(a, b) // 3, 2
let a = 2 let b = ++a console.log(a, b) // 3, 3
!!0 // false !0 true
label: for(let a = 0; a < 10; a++) { if(a === 2) break label; }
switch () { case '': { break; } case '': { break; } default: { break } }
function showMessage() {}
let showMessage = function() {}
function sayHi() { alert('Hello') } let fuc = sayHi; fuc() sayHi()
function ask(question, yes, no) { if (confirm(question)) yes() else no(); } function showOk() { alert( "You agreed." ); } function showCancel() { alert( "You canceled the execution." ); } // 用法:函数 showOk 和 showCancel 被作为参数传入到 ask ask("Do you agree?", showOk, showCancel);
function ask(question, yes, no) { if (confirm(question)) yes() else no(); } ask("Do you agree?", function() {alert('yes')}, function() {alert("no")});