2022常見筆試整理:

1.?預(yù)編譯

1. 創(chuàng)建了ao對象

2. 找形參和變量的聲明作為ao對象的屬性名 值是undefined

3. 實(shí)參和形參相統(tǒng)一

4. 找函數(shù)聲明會覆蓋變量的聲明

Function fn(a,c){

Console.log(a) ?// function a(){}

Var a = 123

Console.log(a) ?// 123

Console.log(c) ???// function c(){}

Function a(){}

If(false){

Var d = 678

}

Console.log(d) ?//undefined

Console.log(b) ?//undefined

Var b = function(){}

Console.log(b) ?// function (){}

Function c(){}

Console.log(c) ?// function c(){}


}

2.?防抖函數(shù)(用于echarts圖,提升性能)

典型案例:(輸入搜索)輸入結(jié)束后n秒才進(jìn)行搜索,n秒內(nèi)又輸入的內(nèi)容,就重新計(jì)算時(shí),解決搜索的bug

Function debounce(delay,callback){

Let timer

Return function(value){

clearTimeout(timer)

timer = setTimeout(function(){

Callback(value)

},delay)

}

}

Function fn(value){

Console.log(value)

}

3.節(jié)流函數(shù):當(dāng)觸發(fā)事件的時(shí)候,保證一段時(shí)間內(nèi)只調(diào)用一次事件處理函數(shù)

Function Thor(fun,wait){

Let tinerOut

Return function(){

If(!timerOut){

timerOut = setTimeout(function(){

Func()

timerOut = unll

},wait)

}

}

}

Function handle({

Console.log(Math.random)

})

Document.getElementById(‘button’).onclick = thro(handle,2000)


3.?js事件循環(huán)機(jī)制(調(diào)用棧-微任務(wù)隊(duì)列-消息隊(duì)列)

Js中的異步操作,比如fetch, setTimeout, setInterval 壓入到調(diào)用棧中的時(shí)候里面的消息會進(jìn)入到消息隊(duì)列中去,消息隊(duì)列中,會等到調(diào)用棧清空后再執(zhí)行。

Eg1:

Function fn1(){

Console.log(1)

}

Function fn2(){

Console.log(2)

Fn1()

Console.log(3)

}

Fn2()

輸出結(jié)果:2,1,3


Eg2:

Function fn1(){

Console.log(1)

}

Function fn2(){

setTimerout(()=>{

Console.log(2)

},0)

Fn1()

Console.log(3)

}

Fn2()

輸出結(jié)果:1,3,2

Promise, async, await的異步操作的時(shí)候會加入到微任務(wù)中去,會在調(diào)用棧清空的時(shí)候立即執(zhí)行,調(diào)用棧中加入的微任務(wù)會立馬執(zhí)行。

Eg:

Var p = new Promise(resolve?=> {

Console.log(4)

Resolve(5)

})

Function fn1(){

Console.log(1)

}

Function fn2(){

setTimerout(()=>{

Console.log(2)

},0)

Fn1()

Console.log(3)

P.then(resolve?=>{

Console.log(resolve)

})

}

Fn2()

輸出結(jié)果:4,1,3,5,2

4.優(yōu)化if(網(wǎng)易2018筆試題)

5.patch方法:

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容