选择题: 选出对应值的答案
Symbol(‘foo’) === Symbol(‘foo’)
false
Number(2) === Number(2)
true
Boolean(false) === Boolean(false)
true
const a = (null || "" || false)
console.log(a) //false
const b = ([] || 0 || true)
console.log(b) // []
const c = (false || {} || null)
console.log(c) // {}
Boolean("")
false
Boolean([])
true
Boolean({})
true
(() => {
let x = (y=10)
})()
console.log(typeof x) 结果是:undefined
console.log(typeof y) 结果是:number
console.log(foo, str, bar); //ƒ foo() {console.log(1)} undefined undefined
function foo() {console.log(1)};
var bar = function() {};
var str = 'hello';
const firstPromise = new Promise((res,rej) => {
setTimeout(res,500,"one")
});
const secondPromise = new Promise((res,rej) => {
setTimeout(res,100,"two")
});
Promise.race([firstPromise, secondPromise]).then(
res => console.log(res)
)
结果是: two 字符串类型
function greeting() {
throw "hello world!";
}
function sayHi() {
try {
const data = greeting();
console.log("IT worked!", data)
}catch(e){
console.log("oh no", e)
}
}
sayHi()
结果是:oh no hello world!
let person = {
name: "lily"
};
const members = [person]
person = null;
console.log(members)
打印结果//
[{name: "lily"}]
var fullname = "a"
var obj = {
fullname: "b",
prop: {
fullname: "c",
getFullname:function() {
return this.fullname
}
}
}
console.log(obj.prop.getFullname()) //c
var test = obj.getFullname
console.log(test); //undefined
简答题:window.onload和DOMContentLoaded的区别是:
1,window.onload在页面上所有dom、样式表,脚本、图片、flash都加载完成时触发。
2,DOMContentLoaded:在页面上dom加载完成时就可以触发。
浏览器的垃圾回收机制:
浏览器的垃圾回收机制:垃圾收集器必须跟踪哪个变量有用,哪个变量没用。对不再有用的变量打上标记,以备将来收回其占用的内存,内存泄漏和浏览器实现的垃圾回收机制息息相关。浏览器实现表示无用变量的策略方法主要有:引用计数、标记清除。
编程题
数组去重
let arr = [1,2,3,4,2,2,3,4,6]
let brr = Array.from(new Set(arr))
console.log(brr) //(5) [1, 2, 3, 4, 6]