javascript學習1

來源:互聯網
上載者:User

標籤:blog   nbsp   div   obj   color   dex   class   throw   oid   

<script type="text/javascript">    var a,b,c,d;    a=(b=5,c=2,d=3);//逗號運算子:它只會返回最後邊的運算式的值    console.log(a);//3                    var a,b,c,d;    a=void(b=3,c=2,d=3);//void強調後面的運算式不會傳回值給a    console.log(a);//undefined                  var a=[1,2];    console.log(a instanceof Array);//a是數組的一個執行個體   true    console.log(a instanceof Object);//所有的對象都是一個Object執行個體                </script>

 

for(變數 in 對象){
  執行的語句塊;
}
作用:
  1.遍曆數組中的所有數組元素.
  2.遍曆javascript對象的所有屬性.

<script type="text/javascript">    var arr=new Array(5);//雖然定義了數組的長度為5,但可以往後賦值    arr[0]=1;    arr[2]=3;    arr[3]="abc";    arr[5]=true;    for(var index in arr){        /*console.log(index);//0 2 3 5*/        console.log(arr[index]);//1 3 abc true    }                     for(var properties in navigator){        console.log("屬性:"+properties+",屬性值:"+navigator[properties]);    }</script>

 

異常拋出語句

<script type="text/javascript">    for(var i=0;i<10;i++){        document.write(i+"</br>");        if(i==5){            throw new Error("報錯了");//在控制台看到報錯效果        }    }    </script>

 

異常捕獲語句

<script type="text/javascript">try{var age=5;if(age==5){  throw new Error("年齡太小了");}}catch(e){document.write("出錯:"+e.message);}finally{document.write("總會執行的finally塊");}</script>

 

with語句

<script type="text/javascript">     //with語句     with(document){        write("輸出第一行資料</br>");        write("輸出第二行資料</br>");        write("輸出第三行資料</br>");     }</script>

 

 

javascript學習1

聯繫我們

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