日日操夜夜添-日日操影院-日日草夜夜操-日日干干-精品一区二区三区波多野结衣-精品一区二区三区高清免费不卡

公告:魔扣目錄網為廣大站長提供免費收錄網站服務,提交前請做好本站友鏈:【 網站目錄:http://www.ylptlb.cn 】, 免友鏈快審服務(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

單選題

JS基礎

js概念與類型檢測

  1. 以下不屬于 typeof 運算符返回值的是?
A. "string"
B. "function"
C. "object"
D. "null"
  1. 執行以下代碼,錯誤的輸出結果是
A. 輸入:typeof {"x":1} 輸出:"object" 
B. 輸入:typeof 1 輸出:"number" 
C. 輸入:typeof [{x:1}] 輸出:"array" 
D. 輸入:typeof NaN 輸出:"number"
  1. 可以用typeof來判斷的基本類型有
A. undefined
B. null
C. array
D. object
  1. 以下不屬于JAVAScript基本數據類型的是:
A. Boolean
B. undefined
C. Symbol
D. Array
  1. 以下關于JavaScript中數據類型的說法錯誤的是()
A. 數據類型分為基本數據類型和引用數據類型
B. JavaScript一共有8種數據類型
C. Object是引用數據類型,且只存儲于堆(heap)中
D. BigInt是可以表示任意精度整數的基本數據類型,存儲于棧(stack)中

答案

DCADC

邏輯判斷

  1. 請選擇結果為ture的表達式?
A. null instanceof Object
B. null === undefined
C. null == undefined
D. NaN == NaN
  1. 下列代碼結果為 true 的是?
A. Symbol.for('a') === Symbol.for('a')
B. Symbol('a') === Symbol('a')
C. NaN === NaN
D. {} === {}
  1. 根據如下變量,下列表達式中返回值為true的是
var a = 1;
var b = [];
var c = '';
var d = true;
A. (a || b) === true
B. (b && c) === true
C. (c && d) === true
D. (d || a) === true
  1. 1==true的返回值是true,這句話是否正確?
A. T
B. F
  1. 下面代碼輸出為true的是?
A. console.log([] === []);
B. console.log(undefined == 0);
C. console.log(undefined == false);
D. console.log(false == '');
  1. 瀏覽器環境下,以下打印結果為true的是
A. console.log("12" === 12)
B. console.log (NaN === NaN)
C. console.log (typeof(null) === typeof(window))
D. console.log ([1,2,3] === [1,2,3])

注意瀏覽器環境與node環境的差別,比如C選項

  1. 以下表達式,正確的是
A. Number('a') == Number('a')
B. -1 == true
C. 3 + '2' === 5
D. ![] == ''

答案

CADADCD

Math

  1. 如何把 7.25 四舍五入為最接近的整數
A. Math.round(7.25)
B. Math.ceil(7.25)
C. round(7.25)
D. Math.rnd(7.25)
  1. 下面哪個選項可以產生0<=num<=10的隨機整數
A. Math.floor(Math.random()*6)
B. Math.floor(Math.random()*10)
C. Math.floor(Math.random()*11)
D. Math.ceil(Math.random()*10)
  1. 以下( )表達式產生一個0~7之間(含0,7)的隨機整數
A. Math.floor(Math.random()*6)
B. Math.floor(Math.random()*7)
C. Math. floor(Math.random()*8)

答案

A CD(注意D) C

字符串

  1. split() 方法用于把一個字符串分割成字符串數組。
A. T
B. F
  1. String對象的哪個方法可以尋找子字符串并返回該子字符串位置
A. match()
B. indexOf()
C. search()
D. concat()

答案

A BC

JSON

  1. 下面哪一個是JSON數據?
A. {name:"xiaoming",age,"student"}
B. {"name":"xiaoming","age":"student"}
C. {"xiaoming","student"}
D. ["xiaoming","student"]
  1. 下面分別使用 JSON.stringify 方法,返回值 res 分別是
const fn = function(){}
const res = JSON.stringify(fn)
const num = 123
const res = JSON.stringify(num)
const res = JSON.stringify(NaN)
const b = true
const res = JSON.stringify(b)
A. 'function'、'123'、'NaN'、'true'
B. undefined、'123'、undefined、'true'
C. undefined、'123'、'null'、'true'
D. undefined、'123'、'null'、undefined

答案

BC

數組

  1. js數組中不會改變原有數組的方法是()
A. push
B. concat
C. sort
D. shift
  1. 下列哪種數組的方法不會修改數組本身
A. slice
B. splice
C. sort
D. unshift
  1. JavaScript中需要往數組末尾處添加一個元素,應該使用以下哪個方法:
A. push
B. pop
C. shift
D. unshift
  1. 以下js操作Array的方法中不能添加元素的是:
A. push
B. pop
C. unshift
D. splice
  1. 數組以下哪個方法會影響原數組?
A. concat
B. splice
C. slice
D. join
  1. JavaScript中,下列哪一個Array的方法的返回值類型和其他不同
A. concat
B. shift
C. filter
D. map
  1. 如下的Array.prototype上的方法中,那個方法不會改變原有的數組?
A. push
B. slice
C. splice
D. sort
  1. 對于一個數字組成的數組 nums,現在需要執行在不改動 nums 的基礎上去重操作,返回一個新的無重復元素的數組,以下幾段代碼能完成這一操作的是()
// (1)
const newNums = Array.from(new Set(nums))
// (2)
const newNums = nums.filter((n, i) => {
    return nums.indexOf(n) === i
})
// (3)
const newNums = nums.forEach((n, i) => {
    return nums.indexOf(n) === i
})
// (4)
const newNums = nums.reduce((acc, n, i) => {
    return [].concat(acc, nums.indexOf(n) === i ? n : []
)
})
A. (1)、(2)、(3)、(4)
B. (1)、(3)、(4)
C. (1)、(2)、(4)
D. (1)、(4)

答案

BAABB
BBC

正則

  1. 正則表達式 ^d+[^d]+ 能匹配下列哪個字符串?
A. 123
B. 123a
C. d123
D. 123def
  1. 下面哪個不是RegExp對象的方法
A. test
B. match
C. exec
D. compile
  1. 以下哪項可以去除變量str中的所有空格
A. str.replace(`/s*/g,""`)
B. str.replace(`/^s|s$/g,""`)
C. str.replace(`/^s*/, ""`)
D. str.replace(`/(s*$)/g, ""`)

答案

CBA

其他

  1. 下列函數哪個不是JavaScript的全局函數
A. encodeURI
B. parseFloat
C. round
D. eval
  1. 編寫高性能JavaScript,以下描述錯誤的是
A. 遵循嚴格模式:"use strict"
B. 將js腳本放在頁面頂部,加快渲染頁面
C. 將js腳本成組打包,減少請求,盡量減少使用閉包
D. 使用非阻塞方式下載js腳本,最小化重繪(repaint)和回流(reflow)
  1. 有關JavaScript中系統方法的描述,錯誤的是?
A. parseFloat方法:該方法將一個字符串轉換成對應的小數
B. isNaN方法:該方法用于檢測參數是否為數值型,如果是,返回true,否則,返回false。
C. escape方法: 該方法返回對一個字符串編碼后的結果字符串
D. eval方法:該方法將某個參數字符串作為一個JavaScript執行題
  1. 下面列出的瀏覽器,無webkit內核的是()
A. chrome
B. Safari
C. 搜狗瀏覽器
D. Firefox
  1. 下列代碼哪個能夠實現獲取形式為 2017-08-01 形式的日期( )?
// A
var formatDate=getDate()
// B
var formatDate = new Date()
// C
var formatDate = function (date) {
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    
    var d = date.getDate();
    return y + '-' + m + '-' + d;
};
// D
var formatDate = function (date) {
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    m = m < 10 ? '0' + m : m;
    var d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    return y + '-' + m + '-' + d;
};
  1. 下面哪一項不能最小化重繪(repaint)和回流(reflow)
A. 需要對元素進行復雜的操作時,可以先隱藏(display:"none"),操作完成后再顯示
B. 需要創建多個DOM節點時,使用DocumentFragment創建完后一次性的加入document
C. 盡量避免用table布局(table元素一旦觸發回流就會導致table里所有的其它元素回流)
D. 盡量不要使用 css 屬性簡寫,如:用border-width, border-style, border-color代替border

答案

CBBDDD

JS深入

this

  1. 下列哪種方法不能改變this指向()
A. eval
B. Apply
C. bind
D. call
  1. 在JavaScript中下面選項關于this描述正確的是
A. 在使用new實例化對象時, this指向這個實例對象
B. 將對象的方法賦值給變量A。執行A()時 該方法中的this指向這個對象。 
C. 在函數定義時,this指向全局變量
D. 在瀏覽器下的全局范圍內,this指向全局對象
  1. 下面有關JavaScript中call和apply方法的描述,錯誤的是?
A. call與apply都屬于Function.prototype的一個方法,所以每個function實例都有call、apply屬性
B. 兩者傳遞的參數不同,call函數第一個參數都是要傳入給當前對象的對象,apply不是
C. apply傳入的是一個參數數組,也就是將多個參數組合成為一個數組傳入
D. call傳入的則是直接的參數列表。call 方法可將一個函數的對象上下文從初始的上下文改變為由 thisObj 指定的新對象。

答案

AAB

作用域(閉包)

  1. 內存泄漏是 javascript 代碼中必須盡量避免的,以下幾段代碼可能會引起內存泄漏的有()
// (1)
function getName() {
    name = 'javascript'
}
getName()
// (2)
const elements = {
    button: document.getElementById('button')
};
function removeButton() {
    document.body.removeChild(elements.button);
}
removeButton()
// (3)
let timer = setInterval(() => {
    const node = document.querySelector('#node') 
    if(node) {
        clearInterval(timer)
    }
}, 1000);
A. (1)、(2)、(3)
B. (2)、(3)
C. (1)、(3)
D. (1)、(2)
  1. 那個操作不會造成內存泄露
A. 沒有清理的DOM元素引用
B. 被遺忘的定時器
C. 事件偵聽沒有移除
D. 局部變量不用時,沒有設為null
  1. 下列關于閉包理解錯誤的是
A. 增加一定的內存消耗
B. 使用不當可能會導致內存泄漏
C. 可以使用閉包模擬私有方法
D. 閉包會改動對象的原型鏈

答案

DDD

原型與繼承

  1. JavaScript實現繼承的方式,不正確的是:
A. 原型鏈繼承
B. 構造函數繼承
C. 組合繼承
D. 關聯繼承
  1. 所有對象都有原型
A. T
B. F
  1. 以下關于原型鏈的描述正確的是:
A. 通過原型鏈繼承的屬性和對象自己定義的屬性等效
B. 通過原型鏈可以模擬對象的私有屬性
C. 在對象上訪問不存在的屬性時,會依次遍歷整條原型鏈
D. 所有 JavaScript 中的對象都是位于原型鏈頂端的 `Object` 的實例

答案

DBC

其他

  1. 以下不屬于前端數據存儲方式的是?
A. jsonp
B. cookie
C. localStorage
D. sessionStorage

答案

A

DOM題

事件流

  1. 將A元素拖拽并放置到B元素中,B元素需要做哪項操作()?
A. event.preventDefault()
B. event.prevent()
C. event.drag()
D. event.drop()
  1. 以下不支持冒泡的鼠標事件為( )?
A. mouseover
B. click
C. mouseleave
D. mousemove
  1. 在javascript中,用于阻止默認事件的默認操作的方法是
A. stopDeafault()
B. stopPropagation()
C. preventDefault()
D. preventDefaultEven()
  1. 事件傳播的三個階段是什么
目標 -> 捕獲 -> 冒泡
冒泡 -> 目標 -> 捕獲
目標 -> 冒泡 -> 捕獲
捕獲 -> 目標 -> 冒泡
  1. 下面有關 javascript 常見事件的觸發情況,描述錯誤的是?
A. onchange:用戶改變域的內容
B. onkeypress:某個鍵盤的鍵被按下或按住
C. onmousedown:某個鼠標按鍵被按下
D. onblur:元素獲得焦點

答案

ACCDD

DOM遍歷

  1. 下列哪項不屬于DOM查找節點的屬性()?
A. parentObj.firstChild
B. parentObj.children
C. neborNode.previousSibling
D. neborNode.siblings
  1. DOM中,給父節點添加子節點的正確方法為()?
A. appendChild(parentNode,newNode);
B. append(parentNode,newNode);
C. parentNode.append(newNode);
D. parentNode.appendChild(newNode);
  1. JavaScript中document.getElementById()返回值的類型為?
A. Array
B. Object
C. String
D. Function
  1. DOM中,給父節點添加子節點的正確方法為()?
A. appendChild(parentNode,newNode);
B. append(parentNode,newNode);
C. parentNode.append(newNode);
D. parentNode.appendChild(newNode);

答案

DDBD

其他

  1. DOM元素的以下屬性改變會導致重排(reflows)的是
outline
visiblity
font-size
background-color

答案

C

BOM題

  1. setInterval(updateClock,60)的含義是( )?
A. 每隔60秒調用一次updateClock()
B. 每隔60毫秒調用一次updateClock()
C. 每隔60分鐘調用一次updateClock()
D. 每分鐘調用60次updateClock()
  1. 使用方法( )可以獲取到地理位置所在的經緯度?
A. Geolocation.watchPosition()
B. Geolocation.getCurrentPosition()
C. Geolocation.getPosition()
D. Geolocation.Position()
  1. setInterval("alert('welcome');",1000);這段代碼的意思是
A. 等待1000秒后,再彈出一個對話框
B. 等待1秒鐘后彈出一個對話框
C. 每隔一秒鐘彈出一個對話框
D. 語句報錯,語法有問題

答案

BBC

ES6題

箭頭函數

  1. 下列對js箭頭函數描述錯誤的是()
A. 箭頭函數沒有原型屬性
B. 箭頭函數不綁定this,會捕獲其所在的上下文的this值,作為自己的this值
C. 箭頭函數可以作為構造函數,使用new
D. 箭頭函數不綁定arguments,取而代之用rest參數解決
  1. 關于箭頭函數下列說法錯誤的一項是:
A. 函數體內this的指向是定義時所在的對象,而不是使用時所在的對象
B. 箭頭函數內不能使用arguments對象
C. 箭頭函數不能使用yield命令
D. 可以使用new創建一個箭頭函數的實例

答案

CD

promise

  1. 關于將 Promise.all 和 Promise.race 傳入空數組的兩段代碼的輸出結果說法正確的是:
Promise.all([]).then((res) => {
    console.log('all');
});
Promise.race([]).then((res) => {
    console.log('race');
});
A. all 和 race 都會被輸出
B. all 和 race 都不會被輸出
C. all 會被輸出,而 race 不會被輸出
D. all 不會被輸出,race 會被輸出
  1. 以下方案中,不是用于解決回調陷阱的的是:
A. Promise
B. Generator
C. async
D. Proxy
  1. 在 ECMAScript6 中,不屬于promise的狀態是:
A. Pending
B. Pause
C. Fulfilled
D. Rejected

答案

CDB

解構賦值

  1. 關于ES6解構表達式,描述正確的是()
let [a,b, c,d, e] = "hello"; 
A. e = "hello";
B. 其它都為undefined
C. 當中 a = "h", b = "e";
D. 語法報錯

答案

C

多選題

JS基礎

  1. 下面哪些數組方法會改變原數組
A. push 
B. concat 
C. splice 
D. map
  1. 下面可以聲明數字的js代碼是
A. const a = 0xa1
B. const a = 076
C. const a = 0b21
D. const a = 7e2
  1. 以下屬于操作符 typeof 的返回值的是:
(1)function
(2) object
(3) null
(4) array
(5) NaN
(6) bigint
(7) regexp
(8) undefined
A. (1)、(2)、(3)、(4)、(5)、(6)、(7)、(8)
B. (1)、(2)、(3)、(8)
C. (1)、(2)、(8)
D. (1)、(2)、(6)、(8)
  1. 以下()結果等于字符串string
A. typeof 'string'
B. String('string').toString()
C. 'string'.split('').sort().join('')
D. (function(string){return string})('string')
E. JSON.parse('{"string":"string"}').string
  1. 下面的等式成立的是?
A. parseInt(46.8) `==` parseFloat(46.8)
B. NaN `!==` NaN
C. isNaN('abc') `==` NaN
D. typeof NaN `===` 'number'
  1. 以下哪些選項可以將集合A轉化為數組?
A. Array.from(A)
B. [].slice.apply(A)
C. [...A]
D. [].map.call(A, o => o)
  1. 下列結果返回 true 的是
A. null == undefined
B. null === undefined
C. null === null
D. NaN == null
E. NaN === NaN
F. Infinity + 1 !== Infinity

答案

AC ABD D ABDE BD ABCD AC

JS深入

  1. 關于以下代碼,說法正確的有哪些?

function Person() { } var person = new Person();

A. 每一個原型都有一個constructor屬性指向關聯的構造函數。
B. 每一個對象都有一個prototype屬性。
C. Object.getPrototypeOf(person) === Person.prototype
D. person.constructor === Person
  1. 下列在 JS 時間循環機制中屬于微任務(microTask)的是?
A. process.nextTick
B. promise
C. setTimeout
D. setInterval

答案

ACD AB

ES6

  1. 以下關于let和const的說法中正確的是:
A. let聲明的變量值和類型都可以改變
B. const聲明的常量不可以改變
C. 兩者都不存在變量提升,同時存在暫時性死區,只能在聲明的位置后面使用
D. const可以先聲明再初始化,可以后賦值
  1. 下面關于Promise說法正確的是(注意“返回結果”的意思包含成功或者失敗)
A. Promise.all在所有給定的promise都fulfilled后才返回結果
B. Promise.race在給定的promise中,某個fulfilled后才返回結果
C. promise.then的回調函數中,可以返回一個新的promise
D. 對于一個向后臺獲取數據已經產生結果的promise:p1,再次調用p1.then,不會去重新發起請求獲取數據

答案

ABC CD

DOM

  1. 下列關于使用 JS 修改元素樣式的代碼,正確的有哪些?
document.body.style.['background-color'] = '#fff'
document.body.style.setProperty('background-color', '#fff')
document.body.style = 'background-color': #fff'
document.body.style.fontSize = '14px'
  1. 下列方法可用于阻止事件冒泡的有
A. event.cancelBubble = true;
B. event.stopPropagation();
C. event.preventDefault();
D. return false;

答案

BCD ABD

填空題

類型檢測

  1. 在JavaScript中,有var arr = []; typeof arr的結果為
  2. 以下使用 typeof 操作符的代碼的輸出結果為
var x = typeof x
var res = typeof typeof x;
console.log(x, res)
  1. [typeof null, null instanceof Object]的結果是什么
  2. typeof typeof 0
  3. JavaScript的typeof運算符的可能結果為array?解釋為什么
  4. 下面代碼的輸出結果是多少?
var arr = [];
console.log(typeof arr, Object.prototype.toString.call(arr));
  1. console.log(Object.prototype.toString.call(undefined))

類型轉換

  1. 表達式 "2"+3+4 的值為
  2. console.log('5' + 3, 5 + '3')
  3. var a=parseInt(“111辦公室”);alert(a);
  4. ["0x1", "0x2", "0x3"].map(parseInt) 的結果
  5. 在js中執行 1+'1'的結果是?
  6. 在js中執行 parseInt('77',40)的結果是?

邏輯判斷

  1. 請給出 [5<6<3,3<2<4] 代碼的運行結果
  2. (2<3)||(3<2) 表達式將返回值為
  3. console.log(true||false&&false, true&&false||true)的輸出結果是?

其他

  1. 1 + - + + + - + 1 的結果是
  2. [ 'a', ,'b', ,].length 的結果是

程序題

JS基礎

  1. 下面兩個程序的輸出結果分別是?
// case 1
function showCase(value) {
    switch(value) {
    case 'A':
        console.log('Case A');
        break;
    case 'B':
        console.log('Case B');
        break;
    case undefined:
        console.log('Case undefined');
        break;
    default:
        console.log('Case default');
    }
}
showCase(new String('A'));
// case 2
function showCase(value) {
    switch(value) {
    case 'A':
        console.log('Case A');
        break;
    case 'B':
        console.log('Case B');
        break;
    case undefined:
        console.log('Case undefined');
        break;
    default:
        console.log('Case default');
    }
}
showCase(String('A'));
  1. p標簽的的內容會顯示什么?
<html>
    <body>
        <p id="demo"></p>
        <script type="text/javascript">
            var x = 10;
            var y = "10";
            document.getElementById("demo").innerHTML = Boolean(x == y);
        </script>
    </body>
</html>
  1. document.write的結果會是什么?
function funcA(x){
    var temp = 4;

    function funcB(y){
        document.write( ++x + y + (temp--));
    }

    funcB(5);
}

funcA(6)
  1. alert的結果會是多少
var varArr = function(i,j,str) {  
    return j == 0 ? str : varArr(i,--j,(str+= " " + i[j]));
}
var arr = new Array('apple','orange','peach','lime');
var str = varArr(arr,arr.length,"");
alert(str);
  1. 下面程序的輸出結果是多少?
function greetingMaker(greeting) { 
    function addName(name) {    
        greeting  = greeting.split(' ').reverse().join("-");
        return greeting + " " + name;
    }
    
    return addName;
}

var daytimeGreeting = greetingMaker("Good Day to you");
alert(daytimeGreeting(name)); 
  1. 下面程序的輸出結果是多少?
String.prototype.GetNum = function() { 
    var regEx = /[^d]/g; 
    return this.replace(regEx, ''); 
};

var str = "a1b2c3";
str = str.GetNum();
alert(str);
  1. 下面程序的輸出結果是多少?
function sum(a, b) {
  return a + b;
}
sum(1, "2");
  1. 下面程序的輸出結果是多少?
var str = "我非常喜歡編程";
str.length = 3;
console.log(str);
  1. 下面程序的輸出結果是多少?
let number = 0;
console.log(number++);
console.log(++number);
console.log(number);
  1. 下面程序的輸出結果是多少?
function nums(a, b) {
    if (a > b)
        console.log('a is bigger')
    else 
        console.log('b is bigger')
    return a + b
}
console.log(nums(4, 2))
console.log(nums(1, 2))
  1. 下面程序輸出結果是多少?
function side(arr) {
    arr[0] = arr[2];
}
function func1(a, b, c = 3) {
    c = 10;
    side(arguments);
    console.log(a + b + c);
}
function func2(a, b, c) {
    c = 10;
    side(arguments);
    console.log(a + b + c);
}
func1(1, 1, 1);
func2(1, 1, 1);
  1. 下面代碼的輸出結果是什么?
var a = 3;
var b = new Number(3);
var c = 3;

console.log(a == b);
console.log(a === b);
console.log(b === c);

  1. 執行下列語句后,a.length的值為?
var a = [];
a.push(1, 2);
a.shift(3, 4);
a.concat([5, 6]);
a.splice(0, 1, 2);
  1. 下面這幾段代碼分別輸出結果是多少?為什么?
var a = {}, b = '123', c = 123;
a[b] = 'b';
a[c] = 'c';
console.log(a[b]);
// example 2
var a = {}, b = Symbol('123'), c = Symbol('123');
a[b] = 'b';
a[c] = 'c';
console.log(a[b]);
// example 3
var a = {}, b = {key:'123'}, c = {key:'456'};
a[b] = 'b';
a[c] = 'c';
console.log(a[b]);
  1. 下面每項的返回值是什么?為什么?
null == undefined
0.1 + 0.2 == 0.3
typeof NaN
typeof Function
typeof Object
typeof {}
'a' + 1
'a' - 1
Function instanceof Object
Object instanceof Function
  1. 下面程序的輸出結果是多少?
var array = []
for(var i = 0; i < 3; i++) {
    array.push(() => i)
}
var newArray = array.map(el => el())
console.log(newArray)
  1. 下面程序的輸出結果是多少?
 function a(m, n) {
        var b = function (l) {
            return l <= m ? l * b(l + 1) : 1;
        }

        return b(m - n + 1);
    }

console.log(a(4, 2));
  1. 下面程序的輸出結果是多少?
console.log(typeof undefined == typeof NULL);
console.log(typeof function () {} == typeof class {});
  1. 執行后a和b.age的值分別為
var a = 10
var b = {
    age: 11
}
function fn(x,y) {
    --y.age;
    return --x;
}
fn(a,b)
  1. 下面程序的執行結果是:
var number = 4;
var numberFactorial = (function (number){
    return (number === 0)? 1: number* factorial(number-1)
})(number)
console.log(numberFactorial)
  1. 下面程序的輸出結果是:
var array = []
for(var i = 0; i < 3; i++) {
    array.push(() => i)
}
var newArray = array.map(el => el())
console.log(newArray)
  1. 下面程序的輸出結果是:
function addToList(item, list) {
    return list.push(item)
}
const result = addToList("nowcoder", ["hello"])
console.log(result)

  1. 下面程序的輸出結果是:
const first = () => { console.log('first'); return false; }
const second = () => { console.log('second'); return true; }
console.log( first() && second() );
console.log( second() || first() );
  1. 下面代碼的輸出結果是:
var s='12ab3cd', arr=s.split(/d/);
console.log(arr[3],arr[4])
  1. 下面程序的輸出結果是:
function getAge(...args) {
  console.log(typeof args);
}

getAge(21);
  1. 下面程序的輸出結果是:
var arr=[1,2,3];
arr.push(arr.shift())
console.log(arr[1],arr[2])

JS深入

this指向

題目解析:this指向題目解析及擴展[3]

關于this還可以看看:可能是最好的 this 解析了...

  1. 下列程序的輸出結果是多少?為什么?
var x = 1;

var obj = {
    x: 3,
    fun:function () {
        var x = 5;
        return this.x;
    }
};

var fun = obj.fun;
console.log( obj.fun(), fun() );

  1. 下列程序的輸出結果是多少?你能理清楚test函數的this指向嗎?
var a = 5;
 function test() { 
    a = 0; 
    alert(a); 
    alert(this.a); 
    var a;
    alert(a); 
}
new test();

  1. 下列程序的輸出結果是多少?為什么?
function fun () {
    return () => {
        return () => {
            return () => {
                console.log(this.name)
            }
        }
    }
}
var f = fun.call({name: 'foo'})
var t1 = f.call({name: 'bar'})()()
var t2 = f().call({name: 'baz'})()
var t3 = f()().call({name: 'qux'})

  1. 執行以下代碼,輸出結果分別是多少?
let obj1 = {
    a: 1,
    foo: () => {
        console.log(this.a)
    }
}
// log1
obj1.foo()
const obj2 = obj1.foo
// log2
obj2()
  1. 下面程序的輸出結果是什么?為什么?
const Person = (name="wang",age=10) => {
this.name = name;
this.age = age;
return this.name +' is '+ this.age + 'years old'
}
let result = new Person('zhang',11)
console.log(result)
  1. 請表述以下代碼的執行結果和原因
var person = {
  age: 18,
  getAge: function() {
    return this.age;
  }
};
var getAge = person.getAge
getAge()
  1. 請按順序寫出打印結果,并說明原因。
var name = 'global';
var obj = {
    name: 'local',
    foo: function(){
        this.name = 'foo';
    }.bind(window)
};
var bar = new obj.foo();
setTimeout(function() {
    console.log(window.name);
}, 0);
console.log(bar.name);
 
var bar3 = bar2 = bar;
bar2.name = 'foo2';
console.log(bar3.name);

  1. 下面程序的執行結果是:
var obj = {
    name:"zhangsan",
    sayName:function(){
        console.info(this.name);
    }
}

var wfunc = obj.sayName;
obj.sayName();
wfunc();
var name = "lisi";
obj.sayName();
wfunc();
  1. 下面程序的輸出結果是:
var name='test' 
var a = {    
    name: 'ass',    
    getName: function() {    
        return this.name;   
    } 
} 
var b = a.getName; 
b();

事件循環

  1. 下列程序的輸出結果分別是多少?為什么?
const promiseA = Promise.resolve('a')
promiseA. then((res) => {
    console.log(res)
}).then((res) => {
    console.log(res)
})
const promiseB = Promise.resolve('b')
promiseB. then((res) => {
    console.log(res)
})
promiseB. then((res) => {
    console.log(res)
})

  1. 下面程序的輸出結果依次是多少?
setTimeout(() => {
    console.log(1)
}, 0)

const P = new Promise((resolve, reject) => {
    console.log(2)
    setTimeout(() => {
        resolve()
        console.log(3)
    }, 0)
})

P.then(() => {
    console.log(4)
})
console.log(5)
  1. 下面程序的輸出結果是
setTimeout(function(){
    console.log(1);
}, 0)
new Promise(function(resolve){
    console.log(2);
    resolve();
    console.log(3);
}).then(function(){
    console.log(4);
})
console.log(5);

  1. 下面程序的輸出結果是?
(async () => {
    console.log(1);
    setTimeout(() => {
        console.log(2);
}, 0);
await new Promise((resolve, reject) => {
    console.log(3);
}).then(() => {
    console.log(4);
});
    console.log(5);
})();

  1. 下面程序的輸出結果是:
new Promise((resolve) => {
    console.log('1')
    resolve()
    console.log('2')
}).then(() => {
    console.log('3')
})
setTimeout(() => {
    console.log('4')
})
console.log('5')
  1. 下面程序的輸出結果是:
var p1 = new Promise(function(resolve, reject){
    resolve("2")
})
setTimeout(function(){
    console.log("1")
},10)
p1.then(function(value){
    console.log(value)
})
setTimeout(function(){
    console.log("3")
},0)

  1. 下面程序的輸出結果是:
setTimeout(function() {
  console.log('setTimeout');
}, 0);
Promise.resolve().then(function() {
  console.log('promise1');
}).then(function() {
  console.log('promise2');
});
  1. 請表述以下代碼的執行結果和原因
setTimeout(function() {
    console.log(1)
},0)
new Promise(function executor(resolve){
    console.log(2)
    for (var i = 0; i<10000; i++) {
        i - 9999 && resolve()
    }
    console.log(3)
}).then(function() {
    console.log(4)
})
console.log(5)
  1. 在網頁中有兩個div塊,html代碼如下
<div class="outer">
 <div class="inner"></div>
</div>

對應的js代碼如下:

var outer = document.querySelector('.outer');
var inner = document.querySelector('.inner');

function onClick() {
    console.log('click');

    setTimeout(function() {
        console.log('timeout');
    }, 0);

    Promise.resolve().then(function() {
        console.log('promise');
    });

    outer.setAttribute('data-random', Math.random());
}

inner.addEventListener('click', onClick);
outer.addEventListener('click', onClick);

當點擊class為inner的div塊時,控制臺依次輸出結果是什么? 10. 下面程序的輸出結果是?

(async () => {
    console.log(1);
    setTimeout(() => {
        console.log(2);
}, 0);
await new Promise((resolve, reject) => {
    console.log(3);
}).then(() => {
    console.log(4);
});
    console.log(5);
})();
  1. 下面程序的輸出結果是:
setTimeout(() => console.log('a'));
Promise.resolve().then(
   () => console.log('b’);
 ).then(
   () => Promise.resolve('c').then(
     (data) => {
       setTimeout(() => console.log('d'));
       console.log('f');
       return data;
     }
   )
 ).then(data => console.log(data));

  1. 下面程序的輸出結果是:
console.log('one'); 
setTimeout(function() { console.log('two'); }, 0); 
Promise.resolve()
       .then(function() { console.log('three'); })
 console.log('four');

  1. 下面程序的執行結果是:
setTimeout(function () {
    console.log(C)
},0)
console.log('D')
new Promise(function(resolve){
    console.log('E')
    resolve()
    console.log('F')
}).then(function() {
    console.log('G')
})
console.log('H')
  1. 有一個輸出函數定義如下:
function log(msg, time) {
  return new Promise((resolve) => {
    setTimeout(() => {
      console.log(msg);
      resolve();
    }, time);
  });
}

則下面三段代碼輸出的結果是:

// 第一段代碼:
(async () => {
  for (let i = 0; i < 5; i++) {
    await log(i, 1000);
  }
})();
// 第二段代碼:
(async () => {
  [ 1, 2, 3, 4 ].forEach(async (i) => {
    await log(i, 1000);
  });
})();
// 第三段代碼:
(async () => {
  for (const i of [ 1, 2, 3, 4 ]) {
    await log(i, 1000);
  }
})();

原型與原型鏈

關于原型JS:看完這篇文章,徹底了解 “原型” & “this”

傳送門: 原型與原型鏈題目解析[4]

  1. 下面程序的輸出結果依次是?
function Fn1(name) {
    if(name){
    this.name = name;
    }
}
Fn1.prototype.name="jack"
let a = new Fn1();
console.log('a:', a.name);

function Fn2(name) {
    this.name = name;
}
Fn2.prototype.name="jack"
let b = new Fn2();
console.log('b:', b.name);
  1. 下面程序的輸出結果是?
var Foo = (function() {
    var x = 0;
    function Foo() {}
    Foo.prototype.increment = function() {
        ++x;
        console.log(x);
    };
    return Foo;
})();
 
var a = new Foo();
a.increment();
a.increment();
var b = new Foo();
a.increment();
  1. 下面程序的輸出結果是?
var name = 'Jay'
function Person(name){
    this.name = name;
    console.log(this.name)
}
var a = Person('Tom')
console.log(name)
console.log(a)
var b = new Person('Michael')
console.log(b)
  1. 請表述以下代碼的執行結果和原因
class A{}
class B extends A{}
const a = new A()
const b = new B()
a.__proto__
b.__proto__
B. __proto__
B. prototype.__proto__
b.__proto__.__proto__
  1. 請表述以下代碼的執行結果和原因
function test() {           
    getName = function() { 
        Promise.resolve().then(() => console.log(0)); 
        console.log(1);               
    };

    return this; 
}
test.getName = function() { 
     setTimeout(() => console.log(2), 0); 
     console.log(3);               
};
test.prototype.getName = function() {    

     console.log(4); 
};       
var getName = function() { 
     console.log(5);             
};
function getName() {

     console.log(6); 
}      
      
test.getName(); 
getName(); 
test().getName(); 
getName();  
new test.getName();
new test().getName();
new new test().getName();

  1. 請表述以下代碼的執行結果和原因
var tmp = {};
var A = function() {};
A. prototype = tmp;

var a = new A();
A. prototype = {};

var b = Object.create(tmp);
b.constructor = A. constructor;

console.log(a instanceof A);
console.log(b instanceof A);

  1. 下面程序的執行結果是:
function Foo(){}
Foo.prototype.z = 3;
var obj = new Foo();
console.info(obj.z)
obj.z = 10;
console.info(obj.z);
delete obj.z;
console.info(obj.z);
  1. 下面程序的執行結果是:
const Book = {
  price: 32
}
const book = Object.create(Book);
book.type = 'Math';
delete book.price;
delete book.type;
console.log(book.price);
console.log(book.type);

作用域與預編譯

  1. 下面的程序會報錯嗎?如果不會,輸出結果分別是多少?
function sayHello() {
    console.log(name);
    console.log(age);
    var name = "Tom";
    let age = 18;
} 
sayHello();
  1. 下面的程序i的打印結果分別是多少?
for (var i = 0; i < 3; i++) {
    setTimeout(_ => {
        console.log(i)
    })
}

for (let i = 0; i < 3; i++) {
    setTimeout(_ => {
        console.log(i)
    })
}
  1. 下面程序的輸出結果是:
console.log(a);
var a = 'a';
console.log(b);
let b = 'b';
  1. 下面程序的輸出結果是:
var foo = "Hello";
(function(){
    var bar = " World";
    alert(foo + bar);
})();
alert(foo + bar);
  1. 下面程序的輸出結果是:
var a = 10;
(function () {
    console.log(a)
    a = 5
    console.log(window.a)
    var a = 20;
    console.log(a)
})()
  1. 下面代碼的輸出結果是:
const a = 10
function runFunction() {
    const a = 20
    console.log('inside', a)
}
runFunction()
console.log('outside', a)
  1. 請描述打印結果并說明原因
"use strict"
var name = 'Jay'
var person = {
    name: 'Wang',
    pro: {
        name: 'Michael',
        getName: function () {
            return this.name
        }
    }
}
console.log(person.pro.getName)
var people = person.pro.getName
console.log(people())
  1. 下面程序的結果是:
<ul>
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
</ul>
<script>
var elements = document.getElementsByTagName("li");
for (var i=0;i<elements.length;i++){
    elements[i].onclick =function( ){
    alert(i); 
    };
}
  1. 下面程序的輸出結果是
compute(10,100);
var compute = function(A,B) {
    console.info(A * B) ;
};
function compute(A,B){
    console.info(A + B);
}
function compute(A,B){
    console.info((A + B)*2);
}
compute(2,10);

  1. 下面程序的執行結果是:
meili()
function meili() {
    console.log("meili")
}
mogu()
var mogu = function() {
    console.log("mogu")
}
  1. 下面兩個代碼片段輸出結果有什么區別?為什么?
// 片段1
check('first');
function check(ars){
    console.log(ars);
}
// 片段2
check('second');
var check= function(ars){
    console.log(ars);
}

ES6

對象

  1. 下面代碼的輸出結果是?
const student = {name: 'ZhangSan'}
Object.defineProperty(student, 'age', {value: 22})
console.log(student)
console.log(Object.keys(student))

generator

  1. 下列程序的輸出結果是多少?為什么?
function * cb(x, y) {
    for(let i = Math.ceil(x); i <= y; i++) {
        yield i;
    }
}

var a = cb(6, 9);
console.log(a.next());
console.log(a.next());

擴展運算符

  1. 下面程序的輸出結果是:
function fn(...args) {
  console.log(typeof args);
}
fn(21);

promise

Promise.reject(0)
       .catch(e => e)
       .catch(e => console.log(e))

class

  1. 請寫出下面ES6代碼編譯后所生成的ES5代碼
class Person {
     constructor (name) {
          this.name = name;
     }
     greet () {
          console.log(`Hi, my name is ${this.name}`);
     }
     greetDelay (time) {
          setTimeout(() => {
               console.log(`Hi, my name is ${this.name}`);
          }, time);
     }
}

標簽模板

  1. 下面程序的輸出結果是多少?
function getPersonInfo (one, two, three) {
    console.log(one)
    console.log(two)
    console.log(three)
}
const person = 'Lydia'
const age = 21
getPersonInfo `${person} is ${age} years old`

module

  1. 請寫出index里面的輸出結果
// module.js
export default () => "Hello world"
export const name = "nowcoder"
// index.js
import * as data from "./module"
console.log(data)

  1. 有a.js和b.js兩個文件,請寫出b文件中代碼的輸出
// a.js
let a = 1
let b = {}
setTimeout(() => {    
a = 2    
b.b = 2
}, 100)
module.exports = { a, b }

// b.js
const a = require('./a')
console.log(a.a)
console.log(a.b)
setTimeout(() => {    
    console.log(a.a)    
    console.log(a.b)
}, 500)

其他

  1. 輸出結果是:
<div id="box1">
    <div id="box2">
        content
    </div>
</div>
<script>
const $ = document.querySelector.bind(document);
const box1 = $('#box1');
const box2 = $('#box2');

box1.addEventListener('click', () =>{
    console.log('box1 true');
}, true);

box1.addEventListener('click', () =>{
    console.log('box1 false');
}, false);

box2.addEventListener('click', () =>{
    console.log('box2 true');
}, true);

box2.addEventListener('click', () =>{
    console.log('box2 false');
}, false);
</script>
  1. 輸出結果是:
$(function () { 
    function fn1( value ) {
        alert( value );
    }
    function fn2( value ) {
        fn1("A");
        return false;
    }
    var callbacks = $.Callbacks();
    callbacks.add( fn1 ); 
    callbacks.fire( "B" );
    callbacks.add( fn2 ); 
    callbacks.fire( "C" );
})
  1. 實現在p元素后添加“Hello World!”,則橫線處應使用的方法為( )?

<html>
    <head>
        <script type="text/javascript" src="/jquery/jquery.js"></script>
        <script type="text/javascript">
            $(document).ready(function(){
                $("button").click(function(){
                    $("<b>Hello World!</b>").______("p");
                });
            });
        </script>
    </head>
    <body>
        <p>This is a paragraph.</p>
        <p>This is another paragraph.</p>
        <button>在每個p元素的結尾添加內容</button>
    </body>
</html>
  1. 輸出結果是:
<div id="box1">
  <div id="box2">
    content
  </div>
</div>
<script>
const $ = document.querySelector.bind(document);
const box1 = $('#box1');
const box2 = $('#box2');
box1.addEventListener('click', () => {
  console.log('box1 true');
}, true);
box1.addEventListener('click', () => {
  console.log('box1 false');
}, false);
box2.addEventListener('click', () => {
  console.log('box2 true');
}, true);
box2.addEventListener('click', () => {
  console.log('box2 false');
}, false);
</script>
  1. 請選擇下面代碼輸出1的次數
var vm = new Vue({  
el: '#example',  
data: {    
    message: 'Hello'  
},  
computed: {    
    test: function () {      
        console.log(1)      
        return this.message    
    }  
},  
created: function (){    
        this.message = 'World'    
        for (var i = 0; i < 5; i++) {        
            console.log(this.test)    
        }  
    }
})

分享到:
標簽:JS
用戶無頭像

網友整理

注冊時間:

網站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網站吧!
最新入駐小程序

數獨大挑戰2018-06-03

數獨一種數學游戲,玩家需要根據9

答題星2018-06-03

您可以通過答題星輕松地創建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學四六

運動步數有氧達人2018-06-03

記錄運動步數,積累氧氣值。還可偷

每日養生app2018-06-03

每日養生,天天健康

體育訓練成績評定2018-06-03

通用課目體育訓練成績評定