JavaScript資料類型與運算子__Java

來源:互聯網
上載者:User

1.原始類型(6種):number,string,boolean,null,undefined,object(Function,Array,Date)


2.隱式轉換:“37”-7  //30

"37"+7 //377

注意巧用+/-規則轉換類型:

(1)num-0  :把num類型轉換為數字;

(2)num+""  :把num類型轉換為字串;


2.  ==運算子

"1.23" == 1.23    :字串和數字進行比較時,會把字串轉化為數字,然後再進行比較;

0 == false;

null == undefined;

new Object() = new Object();

[1,2] == [1,2];


3. ===  嚴格等於

a === b  :

類型不同,返回false;

類型相同:(1)null === null;

                  (2)undefined === undefined;

                    (3) NaN != NaN ;  (NaN和任何數字都不相等);

                    (4)new Object()  != new Object();


4.a==b

類型相同,同===

類型不同,嘗試類型轉換和比較:

(1)null == undefined 相等;

(2)number == string     :會把string轉換為number,   1=="1.0"  //true;

(3)boolean == ?      :會把boolean轉換為數字,true轉換為1,false轉換為0,然後比較;

(4)object == number|string     :嘗試把對象轉換為基本類型,    new String("hi") == "hi"


github首頁:https://github.com/chenyufeng1991  。歡迎大家訪問。

聯繫我們

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