中科大软院春招面试题

好玩的三道题:

function foo(){
var i =0;
  return function(){
  console.log(i++);
  }
}
var foo1 = foo();
var foo2 = foo();
foo1();
foo1();
foo2();
//0 1 0
解析:第一次调用foo1()后,下次不再执行var i= 0了,直接调用return里的函数
html布局:
布局题:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
	<style>
	#father{
		width: 300px;
		border: 1px solid red;
	}
	#child1{
		width: 100px;
		height: 100px;
		background: red;
		float: left;
	}
	#child2{
		width: 100px;
		height: 100px;
		background: blue;
		float: left;
	}
	#next{
		width: 300px;
		height: 300px;
		background: yellow;
	}
	</style>
<body>
<div id="father">
<div id = "child1">div1</div>
<div id="child2">div2</div>
</div>
<div id = "next">hello</div>
</body>
<script>
</script>
</html>
  • 注意下hello的位置,思考下为啥?注意最上方的那条红线为啥?

    关于hello的位置涉及到position和float的区别:
    因为position:absolute是完全脱离文档流,其他盒子与其他盒子内的文本都不会受到影响;而float是一种半脱离状态,被float的元素,文字会环绕到它的旁边。
    红线主要是以为子元素浮动,没有撑开父元素,导致父元素“坍塌”成一条线

面试题三、
function f(n){
	n=n||2;
	return function(x){
		return (x*n);
	}
}
var f2 = f(3);
var f3 = f();
console.log(f2(3));
console.log(f3(3));
console.log(f3(f2(3)));

类似题一,debugger试试?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值