1. 程式人生 > >校招拼多多筆試題(前端工程師)

校招拼多多筆試題(前端工程師)

0)
考試時間:2017-09-02-提前批內推-筆試

為了筆試結束後總結,我考試時截了圖,然後選取幾道有質量的題目。總的來說,坑還是很多的。

測試程式碼:所在倉庫

1)
這裡寫圖片描述

測試程式碼如下:

var a = {};
b = { key: 'b' };
c = { key: 'c' };
a[b] = 123;
a[c] = 456;
console.log(a); //{ '[object Object]': 456 }​​​​​
console.log(a[b]); //456

a[b]通過索引’[object Object]’獲取到物件a的一個屬性。之所以結果是456,是因為a[b]a[c]

獲取到的是同一個屬性,a[c]=456這行程式碼覆蓋了原有屬性。

選D

2)

這裡寫圖片描述

測試程式碼

(function() {
    var a = b = 3;  
})();

console.log(typeof a !== 'undefined'); // false
console.log(typeof b !== 'undefined'); // true

var a = b = 3 這段程式碼是從右往左執行的。先執行b =3 , 由於b在函式內未宣告,所以被認為是全域性變數,所以可以外部被訪問,變數a在函式內被宣告,所以在外部訪問不到。

選A

3)
這裡寫圖片描述

console.log(NaN
== NaN); //false console.log(NaN === NaN); //false console.log(undefined == null); //true console.log(undefined === null); //false

關於NaN:

NaN compares unequal (via ==, !=, ===, and !==) to any other value – including to another NaN value.

選C

4)
這裡寫圖片描述

<!DOCTYPE>
<html>

<head>
    <style
>
</style> </head> <body> <input id="target" type="text"> <script> var input = document.getElementById('#target'); target.onmousedown = function() { console.log('onmousedown'); } target.onmouseup = function() { console.log('onmouseup'); } target.onclick = function() { console.log('onclick'); } target.onfocus = function() { console.log('onfucs'); } </script> </body> </html>

測試結果

onmousedown
onfucs
onmouseup
onclick

選C

5)
這裡寫圖片描述

var a1 = 111;
console.log(a1); //111
console.log(a2); // undefined
console.log(a3); // a3 in not defined
var a2 = 222;
a3 = 333;

var關鍵字的作用是宣告提升。如果只是賦值a3=333並不能提升宣告。而且提升的只是宣告部分,不包括賦值。

選A

6)
這裡寫圖片描述

看文件

new Date();
new Date(value);
new Date(dateString);
new Date(year, month[, date[, hours[, minutes[, seconds[, milliseconds]]]]]);

Parameters

value
Integer value representing the number of milliseconds since 1 January 1970 00:00:00 UTC, with leap seconds ignored (Unix Epoch; but consider that most Unix time stamp functions count in seconds).

dateString
String value representing a date. The string should be in a format recognized by the Date.parse() method (IETF-compliant RFC 2822 timestamps and also a version of ISO8601).

year
Integer value representing the year. Values from 0 to 99 map to the years 1900 to 1999. See the example below.

month
Integer value representing the month, beginning with 0 for January to 11 for December.

date
Optional. Integer value representing the day of the month.

hours
Optional. Integer value representing the hour of the day.

minutes
Optional. Integer value representing the minute segment of a time.

seconds
Optional. Integer value representing the second segment of a time.

milliseconds
Optional. Integer value representing the millisecond segment of a time.

new Date(dateString);這種方式實則呼叫Date.parse(),所以是這樣的:

new Date(Date.parse(dataString))

而Date.parse()這個函式在不同瀏覽器上的行為是不一樣的,所以不符合題意。

選A

7)
這裡寫圖片描述

各種黑科技啊

console.log(1 + '2' + '2'); //122
console.log(1 + +'2' + '2'); //32
// + 是一元操作符 +'2' 實則呼叫Number('2');
console.log(1 + -'1' + '2'); //
// - 也是一元操作符,和+一元操作符相比,除了正負不同,其他同理
console.log(+'1' + '1' + '2'); //112
console.log('A' - 'B' + '2'); // NaN2
// 'A'-'B' 呼叫toString(), NaN-NaN -> NaN,然後字串拼接
console.log('A' - 'B' + 2); //NaN + 2 -> NaN

選D

8)

這裡寫圖片描述

只有在同一個元素上相繼觸發mousedown和mouseup事件,才會觸發click事件,所以

選D

9)

這裡寫圖片描述

直接看結果:

這裡寫圖片描述

答案是都可以的,為什麼呢。

setInterval和setTimeout一樣,不能保證程式從什麼時候開始執行。它內部的程式碼會進入一個訊息佇列,要等到執行棧空閒,且該程式碼在訊息佇列隊首才會執行,所有是有延遲的。

選D

10)

這裡寫圖片描述

<!DOCTYPE>
<html>

<head>
    <style>
        .one {
            z-index: 0;
        }

        .two {
            opacity: 0;
        }

        .three {
            width: 0;
            height: 0;
        }
    </style>
</head>

<body>
    <div class="one">hello world one z-index</div>
    <div class="two">hello world two opacity</div>
    <div class="three">hello world three height = width = 0</div>
    <script></script>
</body>

</html>

測試結果:

這裡寫圖片描述

選B

11)

這裡寫圖片描述

選D

12)
這裡寫圖片描述

基本包裝型別比較的是物件的地址。

var s1 = new String('zxc');
var s2 = new String('zxc');
console.log(s1 == s2);//false
console.log(s1 === s2);//false

13)

這裡寫圖片描述

請讀者自行查閱文件,還是很簡單的。

選B

14)

這裡寫圖片描述

這個可以查閱文件:推薦書籍《圖解HTTP》

選ABCD

15

這裡寫圖片描述

一切引起改變元素位置和幾何的屬性變化都會引起迴流

選ABCD

16)
這裡寫圖片描述

考察排序演算法穩定性,很簡單。

選A,D

17)
這裡寫圖片描述

我對HTTP2.0不是很瞭解,詳見:拼多多考試總結

另外:在HTTP/1,gzip用來壓縮請求體,HTTP2.0用了新技術壓縮請求頭,但不是gzip,詳見HTTP/2 頭部壓縮技術介紹

選BCD

18)
這裡寫圖片描述

選ACD

《JS高階程式設計》第2版P145提到了new關鍵字,new使用時會建立一個新物件,並將建構函式作用域賦給了新物件(因此this指向了新物件)

19)

這裡寫圖片描述

閉包實現

//實則是個閉包
function mul(num) {
    return function(num2) {
        return function(num3) {
            return num * num2 * num3;
        }
    }
}
console.log(mul(2)(3)(4));//24

20)
一道演算法題

這裡寫圖片描述

暴力複雜度有O(N^3)這樣肯定是不行的。

網上找到一種效率更高的,見 此文, 搜O(n2)定位