JavaScript基礎資料型別 (Elementary Data Type)和運算

來源:互聯網
上載者:User

標籤:javaweb

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>無標題文檔</title>
</head>


<script type="text/javascript">
function test1(){
window.alert("你點擊了button");
}
function test2(){
//定義兩個變數並且賦值
var num1=2;
var num2=3;
var res=num1+num2;
window.alert("num1+num2="+res);
}
function test3(){
var name="hello";
window.alert("name的類型是:"+typeof name);
}
function test4(){
var a="hello";
var A="world";
window.alert(a+"--"+A);
}
function test5(){
var n1=0x8a; 
var n2=0010123;
var n3=1234;
alert(n2);


}
function test6(){
var s="abc";
//parseInt() 函數是js的全域函數,可以直接使用
//在哪裡查詢
alert(parseInt(s));
var r=7/0;
alert(r);
}
function test7(){
window.alert("false, 0, “”, null  , undefined、NaN這些表示假");
var a=10;
if(a){alert("真")}
else{alert("假")}
}
function test8(){
window.alert("hello,china");
}
function test9(){
var num1=window.prompt("請輸入第一個數:");
var num2=window.prompt("請輸入第二個數:");
var res=parseFloat(num1)+parseFloat(num2);
window.alert("結果是:"+res);
}
function a(){
window.alert("+ 、-、* 、 / 、%");
}
function b(){
var jia=2+3;
var jian=3-2;
var cheng=2*3;
var chu=6/3;
window.alert(jia+"--"+jian+"--"+cheng+"--"+chu);
}
</script>
<body>
js入門程式<br/>
<input type="button" value="hello,world" onclick="test1()">
<hr width="600px" align="left">
js變數和運算<br/>
<input type="button" value="js變數和運算" onclick="test2()">
<hr width="600px" align="left">
js的變數類型是由js引擎決定,如果要查看某個變數的類型,則可以使用typeof運算子<br/>
<input type="button" value="js變數類型" onclick="test3()">
<hr width="600px" align="left">
變數使用注意事項:<br/>
1.變數區分大小寫<br/>
<input type="button" value="注意1" onclick="test4()">
<hr width="600px" align="left">
js 的資料類型有 <br/>
基礎資料型別 (Elementary Data Type)[1. 整數 2. 實數 3. bool  4. 字串]<br/>
複合資料型別[1. 數組  2.對象]<br/>
特殊資料類型[1. null 2. undefined]<br/>
<input type="button" value="整數" onclick="test5()">
<input type="button" value="實數" onclick="test6()">
<input type="button" value="布爾" onclick="test7()">
<input type="button" value="字元" onclick="test8()">
<hr width="600px" align="left">
js 的資料類型轉換 <br/>
<input type="button" value="js計算機" onclick="test9()">
<hr width="600px" align="left">
js 的運算子 <br/>
<input type="button" value="js運算子" onclick="a()">
<input type="button" value="運算案例" onclick="b()">
<hr width="600px" align="left">
js 位元運算,邏輯運算 <br/>
<a href="http://blog.csdn.net/dzy21/article/details/46986193">參考文章</a>
<hr width="600px" align="left">
</body>

</html>

運行結果:


這些只是必須掌握的知識,要開闊自己的視野要多看js文檔才可以,後面會持續更新。

著作權聲明:博主原創文章,轉載請說明出處。http://blog.csdn.net/dzy21

JavaScript基礎資料型別 (Elementary Data Type)和運算

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.