JavaScript 基本文法

來源:互聯網
上載者:User

標籤:final   gif   oid   數字   arguments   aaa   efault   eval   prot   

標識符
  • 第一個字元,可以是任意Unicode字母(包括英文字母和其他語言的字母),以及貨幣符號($)和底線(_)。
  • 第二個字元及後面的字元,除了Unicode字母、貨幣符號和底線,還可以用數字0-9
JavaScript有一些保留字,不能用作標識符:arguments、break、case、catch、class、const、continue、debugger、default、delete、do、else、enum、eval、export、extends、false、finally、for、function、if、implements、import、in、instanceof、interface、let、new、null、package、private、protected、public、return、static、super、switch、this、throw、true、try、typeof、var、void、while、with、yield。
來源: http://javascript.ruanyifeng.com/grammar/basic.html還有三個詞雖然不是保留字,但是因為具有特別含義,也不應該用作標識符: InfinityNaNundefined


類數組對象的遍曆可以使用和數組對象的遍曆一樣的方法, js使用者自訂錯誤   

下面的例子充分反映了try...catch...finally這三者之間的執行順序。

function f() {  try {    console.log(0);    throw ‘bug‘;  } catch(e) {    console.log(1);    return true; // 這句原本會延遲到finally代碼塊結束再執行    console.log(2); // 不會運行  } finally {    console.log(3);    return false; // 這句會覆蓋掉前面那句return    console.log(4); // 不會運行  }  console.log(5); // 不會運行}var result = f();// 0// 1// 3result// false

上面代碼中,catch代碼塊結束執行之前,會先執行finally代碼塊。從catch轉入finally的標誌,不僅有return語句,還有throw語句。

function f() {  try {    throw ‘出錯了!‘;  } catch(e) {    console.log(‘捕捉到內部錯誤‘);    throw e; // 這句原本會等到finally結束再執行  } finally {    return false; // 直接返回  }}try {  f();} catch(e) {  // 此處不會執行  console.log(‘caught outer "bogus"‘);}//  捕捉到內部錯誤

上面代碼中,進入catch代碼塊之後,一遇到throw語句,就會去執行finally代碼塊,其中有return false語句,因此就直接返回了,不再會回去執行catch代碼塊剩下的部分了。

來源: http://javascript.ruanyifeng.com/grammar/error.html





來自為知筆記(Wiz)

JavaScript 基本文法

相關文章

聯繫我們

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