1. 程式人生 > >記錄一些有意思的前端面試題

記錄一些有意思的前端面試題

1、乘積函式
在這裡插入圖片描述
程式碼

	function mul(){
		let {slice}=Array.prototype;
		let argus=slice.call(arguments,0);

		let returnFn=function(){
			let arguArr=slice.call(arguments,0);
			return mul.apply(null,arguArr.concat(argus))
		}

		returnFn.valueOf=function(){
			return argus.reduce(function(total,item){
				return total*item
			})
		}
		returnFn.toString=null
		return returnFn
	}
	alert(mul(3)(3,3)(4))
	alert(mul(3,10,3))

2、一個表示式的結果

const result=++[[]][+[]]+[+[]];
console.log(result)//?

答案:‘10’
+[ ] => 0
[+[ ]] => [0]
[[]][0] => []
++[] => 1
1+[0] => ‘10’