2. JavaScript資料類型與運算子

來源:互聯網
上載者:User

JavaScript是弱類型語言,在變數聲明時不需要顯式地指定變數的資料類型,而是根據變數的具體內容自動推匯出來,且根據變數內容的改變而自動更改。

一、資料類型

1. 基礎資料型別 (Elementary Data Type)

表1 六種基礎資料型別 (Elementary Data Type)
類型 舉例 簡要說明
Number 45, -12, 32.34,3.7E-2 數值型
String "name", 'hello' 字元型,需加雙引號或單引號
Boolean true, false 布爾型
Undefined
不存在或未被賦初值的變數或對象的屬性
Null null 表示空值
Function var myFun=new Function() 表示函數








2. 組合類別型(Array型和Object型)

    1)Array型

     Array型即為數組,而且數組中各元素可以具有不同的資料類型。 數組本質上市Array對象。

    定義數組

        定義方式1: var arr = [34, 45, 'hello', true]

        定義方式2:var arr = new Array(32,'stmad',3)

    訪問數組元素

        var m = arr[2];

    Array對象的屬性length

        該屬性用於儲存數組的長度,可讀可寫。

    2) Object型,在以後詳細介紹


二、運算子

1. 賦值運算子

    =    +=    -=    *=    /=    %=    &=    ^=    <<=    >>=    >>>=

2. 基本算術運算子

    +    -    *    /    %

3. 位元運算符

    &    ^    |    ~

4. 位移運算子

    >>    <<    >>>

5. 自增和自減

    varA++    ++varA    varA--    --varA

6. 比較子

    ==    !=    >    <    >=    <=

7. 邏輯運算子

    &&    ||    !

8. 逗號運算子 ,

9. 空運算子void

10. (boolCondition)?statementA:statementB;

11. 對象運算子(點運算子、new運算子、delete運算子)

12. typeof運算子:用於表明運算元的資料類型,返回一個字串。



    

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.