js筆試題(不定期更新)

來源:互聯網
上載者:User

標籤:nbsp   log   第一個   turn   之間   ec2   type   功能   div   

1 找出數字數組中最大的元素(使用Math.max函數)
Math.max.apply(this, arr)
View Code

 

2 轉化一個數字數組為function數組(每個function都彈出相應的數字)
for(var i=0;i<arr.length;i++){    var tmp=arr[i];    arr[i]=function(tmp){        return function(){            alert(tmp);        }    }(tmp)}或者arr.map(function(e){    return function(){alert(e)};});
View Code

 

3 給object數組進行排序(排序條件是每個元素對象的屬性個數)
objArray.sort(function(a,b){    return Object.keys(a).length-Object.keys(b).length;});
View Code

 

4 利用JavaScript列印出Fibonacci數(不使用全域變數)
function Fibonacci(n) {    if(n==0||n==1){        return n;    }    return Fibonacci(n-1)+Fibonacci(n-2);}Fibonacci(5);
View Code

 

5 實現如下文法的功能:var a = (5).plus(3).minus(6); //2
Number.prototype.plus=function(n){    return this+n;}Number.prototype.minus=function(n){    return this-n;}
View Code

 

6 實現如下文法的功能:var a = add(2)(3)(4); //9
//判斷返回的是函數還是值function add(n){    var f=function(m){        return add(n+m);    };    f.toString=f.valueOf=function(){        return n;    };    return f;}
View Code

 

7 變數提升
if (!("a" in window)) {    var a = 1;}alert(a);
//[alert: undefined]
View Answer 8 變數對象
var a = 1,    b = function a(x) {        x && a(--x);    };alert(a);
// [alert: 1]// 優先順序: 函數的形參 > 函數申明 > 變數申明// 相當於函數運算式   b = function(x) {//        x && b(--x);//    };
View Answer

 

function a(x) {    return x * 2;}var a;alert(a);
// alert: function a(x) {//     return x * 2;// }
View Answer

 

9  Arguments對象
function b(x, y, a) {    arguments[2] = 10;    alert(a);}b(1, 2, 3);function b(x, y, a) {    arguments[2] = 10;    alert(a);}b(1, 2);
// alert: 10 和 alert:undefined// properties-indexes 的值和實際傳遞進來的參數之間是共用的。// 這個共用其實不是真正的共用一個記憶體位址,而是2個不同的記憶體位址,使用JavaScript引擎來保證2個值是隨時一樣的,當然前提是這個索引值要小於傳入的參數個數。
View Answer

 

10 This
function a() {    alert(this);}a.call(null);
// alert: [object Window]// 如果第一個參數傳入的對象調用者是null或者undefined的話,call方法將把全域對象作為this的值。
View Answer

 

 

 

44道JS難題

 

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.