记录一些有意思的前端面试题

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’

猜你喜欢

转载自blog.csdn.net/weixin_43801564/article/details/85712043