標籤:
<html><head><title>javascript基礎</title></head><body>1.NaN isNaN()</br><script type="text/javascript"> //資料類型轉換失敗 返回NaN類型 document.write("parseInt(‘a‘) : " ,parseInt(‘a‘),"<br/>"); document.write("parseInt(‘9‘) : " ,parseInt(‘9‘),"<br/>"); document.write("NaN == NaN : " , NaN == NaN,"<br/>");</script> 2.關係運算子 > >= < <= != == ===</br><script type="text/javascript"> document.write("‘7‘ < 5 : " ,‘7‘ < 5,"<br/>");//發生類型轉換 document.write("‘7‘ > 5 : " ,‘7‘ > 5,"<br/>"); document.write("‘7‘ > ‘12‘ : " ,‘7‘ > ‘12‘,"<br/>");//不發生類型轉換 document.write("‘a‘ > 12 : " ,‘a‘ > 12,"<br/>");//發生類型轉換 document.write("‘a‘ < 12 : " ,‘a‘ < 12,"<br/>");//發生類型轉換 document.write("isNaN(‘a‘) : " ,isNaN(‘a‘) ,"<br/>");//是否是非數字 document.write("isNaN(‘8‘) : " ,isNaN(‘8‘) ,"<br/>"); document.write("100 == ‘100‘ : " , 100 == ‘100‘ ,"<br/>"); document.write("100 === ‘100‘ : " , 100 === ‘100‘ ,"<br/>");//值相等 類型相同 document.write("‘100‘ === ‘100‘ : " , ‘100‘ === ‘100‘ ,"<br/>");</script> 3.賦值運算子 = += -= *= /= %=</br>4.邏輯運算子 !&& ||</br><script type="text/javascript"> //任何類型使用!結果是布爾型 true --- null ‘‘ 0 undefined document.write("!true : " , !true ,"<br/>"); document.write("!5 : " , !5 ,"<br/>"); document.write("!0 : " , !0 ,"<br/>"); document.write("!-2 : " , !-2 ,"<br/>"); document.write("!null : " , !null ,"<br/>"); document.write("!new Date() : " , !new Date() ,"<br/>");</script> 5.類型轉換</br><script type="text/javascript">document.write("parseInt(‘123‘) : " ,parseInt(‘123‘),"<br/>");document.write("parseInt(‘123a‘) : " ,parseInt(‘123a‘),"<br/>");document.write("parseInt(‘a123‘) : " ,parseInt(‘a123‘),"<br/>");document.write("parseInt(‘123.456‘) : " ,parseInt(‘123.456‘),"<br/>");document.write("parseFloat(‘123.456‘) : " ,parseFloat(‘123.456‘),"<br/>");document.write("parseFloat(‘123.456.789‘) : " ,parseFloat(‘123.456.789‘),"<br/>");document.write("parseFloat(‘123.a.789‘) : " ,parseFloat(‘123.a.789‘),"<br/>");document.write("parseFloat(‘a123.789‘) : " ,parseFloat(‘a123.789‘),"<br/>");var a = 20;var b = 50;document.write("a + b = " ,a + b,"<br/>");document.write("a.toString() + b = " ,a.toString() + b,"<br/>");document.write("‘10‘ + b = " ,‘10‘ + b,"<br/>");//字串 串連document.write("‘10‘ - b = " ,‘10‘ - b,"<br/>");//類型轉換 進行計算document.write("‘a‘ - b = " ,‘a‘ - b,"<br/>");</script> </body></html>
結果:
2.
javascript 基礎1第11節