/if(condition){
statement;
}/ //条件语句,条件的求值结果永远是一个布尔值,只能是true和false。
/if(1>2){
alert(“The world is gine mad!”)}/
//1>2返回的是false,该语句不会执行。花括号可以提升脚本可读性,有利于文本压缩。
var a = 8;
if (1 > 2) {
alert(“The world is gone mad”)
}
else { “All is well with the world.” }
//比较操作符 是比较操作符而=是赋值符,这个不要弄混。
var myMood = “happy”, yourMood = “shappy”;
if (myMood = yourMood) {
alert(“Both u and me feel the same!”)
}// =h会比较数据的类型,如false和”“ 空字符串在中比较的是值,他们的值在比较是相等的,即false和空字符串判断时值相等。严格不相等用!
//opersnd 逻辑比较,可把多个逻辑操作组合在一起,
if (a >= 5 && a < 10); {//& & 与字符,子条件全文真才为真,有一假,全为假。
alert(“the number is inx the right range .”)
}//逻辑操作操作的对象是布尔值,
if (a > 10 || a < 5) {
alert(“The number is not in the right rage”);// ||或操作符,有一直则为真,全假才为假
}
if (!(1 > 2)) { alert(“All is well with the world!”) }// ! 逻辑非操作符,让取值的布尔值颠倒,对整个语句的布尔值进行颠倒,注意括号的使用。
if (!(a > 10 || a < 5)) {
alert(“The number is in the right rage.”
)
}