JS面試基礎

來源:互聯網
上載者:User

標籤:物件類型   func   實作類別   基礎   建立   模組化   列印   fine   string   

問題:

1.JS中typeof能夠得到哪些類型?

考點:JS 的變數類型

2.何時用 雙等於 == ?何時用 三等 ===?

考點:強制類型轉換

3.window.onload 與 DOMContentLoaded的區別。

4.用JS建立10個<a>標籤 ,點擊的時候彈出來對應的序號 。

考點:範圍 

5.簡述如何?一個模組載入器,實作類別似require.js的基礎功能。

考點:JS的模組化 

6.實現數組的隨機排序

考點:JS的基礎演算法。

 

1.變數分為實值型別和參考型別。

var a = 100;

var b = a;

a = 200;

console.log(b);   //列印出來的是100;

 

var a = { age : 20 };

var b = a;

b.age = 21;

console.log(a.age);   // 列印出來的是21 

對象 數組 函數都是 參考型別 

typeof undefined    //undefined ;

typeof "ab"   //string 

typeof 123 //number 

typeof ture //boolean 

typeof 對於實值型別是可以區分的 

 

typeof { }                      //object 

typeof [ ]                     //object 

typeof null                 //object           null 指標 不指向任何的對象 

typeof console.log            //function 

typeof 區分實值型別 但是不能區分參考型別 ,除了函數之外 其他的都不能區分,只是知道是物件類型 object 類型   ,另外參考型別可以無限制的擴充屬性 

 

2 .  強制類型轉換 

字串拼接    ==(雙等號)運算子      if語句    邏輯運算   都是可以強制類型轉換的 

var a = 100 + 10   ;

console.log(a);   // 110  number 類型的 

 

var  b = 100 + "10"   ;

console.log(b);  //  “10010”  string 類型的 ,因為  +  號 ,做了輕質類型轉換了,把數字變成了字串,然後串連在一起了。

 

100 == " 100 "      //true ;

0  == " "       //true ;       Null 字元串 

null == undefined   //true ;   null  和  undefined  兩個本身都可以轉換成 false  ,所以可以相等  。

 

JS面試基礎

相關文章

聯繫我們

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