JavaScript詞法範圍經典練習題

來源:互聯網
上載者:User

標籤:lang   java   utf-8   練習   color   class   ==   rip   範圍   

<!DOCTYPE html><html lang="zh-CN"><head>  <meta charset="UTF-8">  <title>Title</title></head><body><script> //1 ==================================================== var a; if (‘a‘ in window) {   var a = 10; } alert(a);  // 10//  注:  in 是一個關鍵字  用於判斷 ‘屬性‘ in 對象  當前這個屬性是否是對象的屬性//2 ==================================================== var foo = 1; function bar() {   if (!foo) {     var foo = 10;   }   alert(foo); //  10//      預解析階段://       var foo;//      代碼執行階段:       if(!foo){         foo = 10;       }       alert(foo); } bar(); // 代碼拆分://  預解析階段: var foo; function bar(){} // 代碼執行階段: foo = 1; bar();    //3 ============================================================ var num = 123; function f1(num) {//    var num = 456;   console.log(num); // 456 } function f2() {   var num = 456;   f1(num);//f1(456) } f2();    //4 ===================================================================== function fn(){   var a = 1, b = 1, c = 1;//    var a = 1;//    var b = 1;//    var c = 1; } fn(); console.log(c); //1  e console.log(b); //1  e console.log(a); //e  e function fn1(){   var a = b = c = 1;   var a = 1;   b = 1;   c = 1; } fn1(); console.log(c); // 1 console.log(b); // 1 console.log(a); // e    //5 ================================================================ var a ; function a(){   console.log(‘呵呵‘)   function a(){     a = 4;     console.log(‘哈哈‘)   }   a();   console.log(a);  // 4 } a(); console.log(a); // 外面的a   //6  =================================================================== var a = 1; function a(){   a++; } console.log(a) //1    // 7 ===================================================================== var a = { x : 1 } var b = a; a.x = a = { n : 1}; console.log(a.x); // undefined console.log(b.x); //  {n : 1}  </script></body></html>

 

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.