(7)JavaScript學習筆記 – 運算子(續)

來源:互聯網
上載者:User

一、帶操作的賦值運算子

1.+= 執行加法和賦值運算

total+=sales_tax;//等同於total=total+sales_tax;

二、條件運算子
1.三元運算子

greeting = "hello" + (username != null ? username : "there");//等價於greeting = "hello";if(username != null)   greeting += username;else   greeting += "there";

三、typeof 運算子
1.放在一個運算數之前,傳回值是一個字串,說明此運算數的類型;

2.數字返回“number”,字串返回“string”,布爾值返回“boolean”,對象、數組和null 返回的都是“object”,對函數返回的是“function”,未定義的返回的是“undefined”

四、數組和對象存取運算子
1.使用[ ] 來存取數組的元素,使用 . 來存取對象的元素;

2. . 左邊的是對象,右邊的是一個標識符(屬性名稱),必須是該對象的屬性或方法的直接量名,而且不需要指明類型

document.LastModified;navigator.appName;frame[0].length;document.write("hello world");

3.如果 [ ] 左邊的是一個數組,右邊的必須是一個整數

frames[1];document.forms[i + j];document.forms[i].elements[j++];

4.如果 [ ] 左邊是一個對象,右邊應該是一個值為字串的運算式,他指明該對象的一個屬性;

document["LastModified"];frames[0]['length'];data["val" + i];

 

相關文章

聯繫我們

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