var a=10;
var b=0;
if(a>b){
console.log(a);
}else{
console.log(b);
}
//條件判斷如果得到的不是boolean值,自動(dòng)調(diào)用Boolean()方法
if(a){
console.log(a);
}
if(b){
console.log(b);
}else{
console.log("0的Boolean值是false");//如果頁面沒定義中文字符集可會(huì)回打印亂碼
}
var i=0
do{
i+=3;
console.log(i);
}while(i<10)
//結(jié)果:3 6 9 12
var x=3;
while(x>0){
console.log(--x);
}
//結(jié)果:2 1 0
for(var i=0 ;i<3;i++){
console.log(i);
}
//結(jié)果:0 1 2
for(var property in window){
console.log(property);
}
//打印window里面的每一個(gè)屬性,
//最好做null和undefined判斷,老的瀏覽器版本會(huì)有異常
//with僅僅是一種簡(jiǎn)化的操作,但是對(duì)于調(diào)試和性能來說并不好
console.log(location.search.substring(1));//
console.log(location.hostname);//
console.log(location.href);//
with(location){
console.log(search.substring(1));//
console.log(hostname);//
console.log(href);//
}
switch,基本和c/java一樣,后面要有break;否則會(huì)直接執(zhí)行
var a=10;
switch(a){
case 3:console.log(3);break;
case 10:console.log(10);break;
default:console.log(a);break;
}
a=9;
switch(a){
case 3:console.log(3);break;
case 10:console.log(10);break;
default:console.log(a);break;
}
最后編輯于 :2017.12.05 05:49:20
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者 【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。 平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。