1. ["1", "2", "3"].map(parseInt)
-
-
解析:
parseInt (val, radix) :兩個參數,val值,radix基數(就是多少進制轉換)
-
map 能傳進回調函數
3參數 (element, index, array)
-
-
-
-
鞏固:[
"1", "1", "11","5"].map(parseInt)
2. [typeof null, null instanceof Object]
-
-
解析:
null表明空對象指針,因此typeof判斷成一個對象。能夠說JS設計上的一個BUG
-
instanceof 實際上判斷的是對象上構造函數,null是空固然不可能有構造函數
-
3. [ [3,2,1].reduce(Math.pow), [].reduce(Math.pow) ]
-
-
解析:
Math.pow (x , y) x 的 y 次冪的值
-
-
fn (total, currentValue, currentIndex, arr)
-
若是一個函數不傳初始值,數組第一個組默認爲初始值.
-
[
3,2,1].reduce(Math.pow)
-
-
-
-
-
-
4.
-
-
console.log(
'Value is ' + (val === 'smtg') ? 'Something' : 'Nothing');
這段代碼的執行結果?javascript
-
-
-
因此原題等價於
'Value is true' ? 'Somthing' : 'Nonthing'
-
而不是
'Value is' + (true ? 'Something' : 'Nonthing')
-
5.
-
-
-
if (typeof name === 'undefined') {
-
-
console.log('Goodbye ' + name);
-
-
console.log('Hello ' + name);
-
-
這段代碼的執行結果?java
-
-
解析:(
1)typeof時 name變量提高。 在函數內部之聲明未定義
-
-
-
-
-
if (typeof name === 'undefined') {
-
-
console.log('Goodbye ' + name);
-
-
console.log('Hello ' + name);
-
-
-
答案:Hello World 由於name已經變成函數內局部變量
6.
-
var END = Math.pow(2, 53);
-
-
-
for (var i = START; i <= END; i++) {
-
-
-
這段代碼的執行結果?es6
-
-
解析:js中能夠表示的最大整數不是
2的53次方,而是1.7976931348623157e+308。2的53次方不是js能表示的最大整數而應該是能正確計算且不失精度的最大整數,
-
-
-
-
-
for (var i = START; i <= END; i++) {
-
-
-
-
7.
-
-
-
ary.filter(
function(x) { return x === undefined;});
這段代碼的執行結果?web
-
-
解析:filter() 不會對空數組進行檢測。會跳過那些空元素
-
-
var ary = [0,1,2,undefined,undefined,undefined,null];
-
ary.filter(
function(x) { return x === undefined;});
-
8.
-
-
-
-
-
[
two - one == one, eight - six == two]
這段代碼的執行結果?chrome
-
-
解析:IEEE
754標準中的浮點數並不能精確地表達小數
-
-
-
-
-
( eight - six ).toFixed(
4) == two
-
9.
-
function showCase(value) {
-
-
-
-
-
-
-
-
-
console.log('undefined');
-
-
-
console.log('Do not know!');
-
-
-
showCase(
new String('A'));
這段代碼的執行結果?數組
-
-
-
10.
-
function showCase2(value) {
-
-
-
-
-
-
-
-
-
console.log('undefined');
-
-
-
console.log('Do not know!');
-
-
-
這段代碼的執行結果?瀏覽器
-
-
11.
-
-
-
-
-
-
-
-
return isEven(num) || isOdd(num);
-
-
var values = [7, 4, '13', -9, Infinity];
-
這段代碼的執行結果?app
-
答案:[
true, true, true, false, false]
-
解析:%若是不是數值會調用
Number()去轉化
-
-
-
-
12.
-
-
-
這段代碼的執行結果?函數
-
-
13.
Array.isArray( Array.prototype )
這段代碼的執行結果?ui
-
-
-
數組的原型是數組,對象的原型是對象,函數的原型是函數
14.
-
-
-
-
-
-
這段代碼的執行結果?
-
-
-
15.[]==[]
-
-
-
-
(
1)! 的優先級高於== ,右邊運算結果等於 false
-
(
2)一個引用類型和一個值去比較 把引用類型轉化成值類型,左邊0
-
(
3)因此 0 == false 答案是true
16.
-
-
這段代碼的執行結果?
-
-
17. 1 + - + + + - + 1
-
-
18.
-
-
-
ary.map(
function(elem) { return '1'; });
這段代碼的執行結果?
-
-
19.
-
function sidEffecting(ary) {
-
-
-
-
-
sidEffecting(
arguments);
-
-
-
這段代碼的執行結果?
-
-
-
-
function sidEffecting(ary) {
-
-
-
-
-
sidEffecting(
arguments);
-
-
-
-
20.
-
var a = 111111111111111110000,
-
-
這段代碼的執行結果?
-
-
解析:在JavaScript中number類型在JavaScript中以
64位(8byte)來存儲。這64位中有符號位1位、指數位11位、實數位52位。2的53次方時,是最大值。其值爲:9007199254740992(0x20000000000000)。超過這個值的話,運算的結果就會不對.
21.
-
-
這段代碼的執行結果?
-
-
22.Number.MIN_VALUE > 0
-
-
解析:MIN_VALUE 屬性是 JavaScript 中可表示的最小的數(接近
0 ,但不是負數)。它的近似值爲 5 x 10-324。
23.[1 < 2 < 3, 3 < 2 < 1]
-
-
-
true < 3 => 1 < 3 => true;
-
-
-
false < 1 => 0 < 1 => true;
24.2 == [[[2]]]
-
-
-
25.
-
-
-
這段代碼的執行結果?
-
-
解析:由於在
js 中 1.1, 1., .1 都是合法的數字. 那麼在解析 3.toString 的時候這個 . 究竟是屬於這個數字仍是函數調用呢? 只能是數字, 由於3.合法啊!
26.
-
-
-
-
-
這段代碼的執行結果?
-
-
-
-
27.
-
-
-
-
這段代碼的執行結果?
-
-
解析:正則是對象,引用類型,相等(==)和全等(===)都是比較引用地址
28.
-
-
-
-
-
-
-
這段代碼的執行結果?
-
答案:
false, false, false, true
-
解析:相等(==)和全等(===)仍是比較引用地址
-
引用類型間比較大小是按照字典序比較,就是先比第一項誰大,相同再去比第二項。
29.
-
var a = {}, b = Object.prototype;
-
[a.prototype === b,
Object.getPrototypeOf(a) === b]
這段代碼的執行結果?
-
-
解析:
Object 的實例是 a,a上並無prototype屬性
-
a的__poroto__ 指向的是
Object.prototype,也就是Object.getPrototypeOf(a)。a的原型對象是b
30.
-
-
var a = f.prototype, b = Object.getPrototypeOf(f);
-
這段代碼的執行結果?
-
-
解析:a是構造函數f的原型 : {
constructor: ƒ}
-
b是實例f的原型對象 : ƒ () { [
native code] }
31.
-
-
-
-
這段代碼的執行結果?
-
-
32."1 2 3".replace(/\d/g, parseInt)
-
-
-
-
-
-
-
若是沒有與子表達式匹配的項,第二參數爲出現的位置.因此第一個參數是匹配項,第二個參數是位置
-
-
-
-
-
"And the %1".replace(/%([1-8])/g,function(match,a , b ,d){
-
console.log(match +" "+ a + " "+ b +" "+d )
-
-
33.
-
-
var parent = Object.getPrototypeOf(f);
-
-
-
-
這段代碼的執行結果?
-
答案:
"f", "Empty", "function", error
-
-
-
先計算
eval(f.name) 爲 f,f的數據類型是function
-
eval(parent.name) 爲undefined, "undefined"
34.
-
var lowerCaseOnly = /^[a-z]+$/;
-
lowerCaseOnly.test(
null), lowerCaseOnly.test()]
這段代碼的執行結果?
-
-
解析:這裏
test 函數會將參數轉爲字符串. 'nul', 'undefined' 天然都是全小寫了
35.[,,,].join(",")
-
-
解析:由於javascript 在定義數組的時候容許最後一個元素後跟一個,
-
-
鞏固: [,,
1,].join(".").length
36.
-
var a = {class: "Animal", name: 'Fido'};
-
這段代碼的執行結果?
-
-
解析:這取決於瀏覽器。類是一個保留字,可是它被Chrome、Firefox和Opera接受爲屬性名。在另外一方面,每一個人都會接受大多數其餘保留詞(
int,私有,拋出等)做爲變量名,而類是VordBoint。
37.var a = new Date("epoch")
-
-
解析:您獲得「無效日期」,這是一個實際的日期對象(一個日期的日期爲
true)。但無效。這是由於時間內部保持爲一個數字,在這種狀況下,它是NA。
-
-
正確的是格式是var d =
new Date(year, month, day, hours, minutes, seconds, milliseconds);
38.
-
-
b =
new Function().length
-
這段代碼的執行結果?
-
-
解析:首先
new在函數帶()時運算優先級和.同樣因此從左向右執行
-
-
-
-
-
-
39.
-
-
-
-
[a === b, b === c, a === c]
這段代碼的執行結果?
-
答案:[
false, false, false]
-
解析:當日期被做爲構造函數調用時,它返回一個相對於劃時代的對象(
JAN 01 1970)。當參數丟失時,它返回當前日期。當它做爲函數調用時,它返回當前時間的字符串表示形式。
-
-
-
-
-
-
-
-
"Tue Jun 12 2018 14:36:24 GMT+0800 (CST)" 固然若是a,b執行時間相差1秒則爲false
40.
-
var min = Math.min(), max = Math.max()
-
這段代碼的執行結果?
-
-
解析:
Math.min 不傳參數返回 Infinity, Math.max 不傳參數返回 -Infinity
-
-
鞏固:
Number.MAX_VALUE > Number.MIN_VALUE
41.
-
function captureOne(re, str) {
-
var match = re.exec(str);
-
return match && match[1];
-
-
var numRe = /num=(\d+)/ig,
-
-
a1 = captureOne(numRe,
"num=1"),
-
a2 = captureOne(wordRe,
"word=1"),
-
a3 = captureOne(numRe,
"NUM=2"),
-
a4 = captureOne(wordRe,
"WORD=2");
-
這段代碼的執行結果?
-
-
解析: /g有一個屬性叫lastIndex,每次匹配若是沒有匹配到,它將重置爲
0,若是匹配到了,他將記錄匹配的位置。咱們看一個簡單的例子吧。
-
-
numRe.test(
"num=1abcwewe")
-
-
-
42.
-
var a = new Date("2014-03-19"),
-
b =
new Date(2014, 03, 19);
-
[a.getDay() === b.getDay(), a.getMonth() === b.getMonth()]
這段代碼的執行結果?
-
-
解析:
var a = new Date("2014-03-19")
-
Wed Mar
19 2014 08:00:00 GMT+0800 (CST)
-
b =
new Date(2014, 03, 19);
-
Sat Apr
19 2014 00:00:00 GMT+0800 (CST)
-
-
-
-
鞏固: [a.getDate() === b.getDate()]
43.
-
if ('http://giftwrapped.com/picture.jpg'.match('.gif')) {
-
-
-
-
這段代碼的執行結果?
-
-
解析:
String.prototype.match 接受一個正則, 若是不是, 按照 new RegExp(obj) 轉化. 因此 . 並不會轉義 。 那麼 /gif 就匹配了 /.gif/
-
鞏固:
if ('http://giftwrapped.com/picture.jpg'.indexOf('.gif')) {
-
-
-
-
-