# 前端面试题收集

``````function A(){
}
function Fn(){
A = function(){
}
return this
}
Fn.A = A
Fn.prototype = {
A: () => {
}
}
A()
Fn.A()
Fn().A()
new Fn.A()
new Fn().A()
new new Fn().A()
``````

``````1
1
2
1
3

``````

``````var x = 2
var y = {
x: 3,
z: (function(x){
this.x = x
x += 3
console.log(x)
})(x)
}
var m = y.z
m(4)
y.z(5)
console.log(x,y.x)
``````

``````5

``````

``````var x = 0,
y = 1
function fn(){
x += 2
fn = function(y){
console.log(y + (--x))
}
console.log(x,y)
}
fn(3)
fn(4)
console.log(x,y)
``````

``````2 1
5
1 1
``````

``````setTimeout(() => {
console.log(1)
},20)
console.log(2)
setTimeout(() => {
console.log(3)
},10)
console.log(4)
console.log('AA')
for(let i = 0;i < 9000000;i++){
// do soming
}
console.timeEnd('AA')
console.log(5)
setTimeout(() => {
console.log(6)
},8)
console.log(7)
setTimeout(()=>{
console.log(6)
},8)
console.log(7)
setTimeout(()=>{
console.log(8)
},15)
console.log(9)
``````

``````2
4
AA
Timer 'AA' does not exist
5
7
7
9
undefined
3
1
6
6
8
``````

``````// a等于什么值条件会成立？
var a = ?
if(a ==1 && a ==2 && a ==3){
console.log('条件成立')
}
``````

``````方案1：
a = {
i: 0,
toString(){// valueOf也行
return ++this.i
}
}

var i = 0
Object.defineProperty(window,'a',{
get(){
return ++i
}
})

var a = [1,2,3]
a.toString = a.shift
``````

1. 对象==字符串 就是对象.toString()变为字符串
2. null==undefined 相等 但是和其他值比较就不相等
3. NaN==NaN 不相等
4. 剩下的都是转换为数字 例如：'1' == true 就是 1 == 1