首页 > 其他分享 >前端部分面试题目整理

前端部分面试题目整理

时间:2022-11-14 12:39:13浏览次数:45  
标签:function 题目 name Title 前端 面试 func var xo

1.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
var name='武老板';
function func(){
var name='李杰';
function inner() {
alert(name);
}
return inner;
}
var ret=func();
ret()
</script>
</body>
</html>

测试结果:

前端部分面试题目整理_javascript

2.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script type="text/javascript">

function main() {
if (1 == 1) {
var name = '武老板';
}
console.log(name);
}
main()
</script>
</body>
</html>

测试结果:
  没有打印出任何东西

3.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
xo='alex';
function func() {
var xo = '武老板';
function inner() {
var xo='老男孩';
console.log(xo);
}
inner();
}
func();
</script>
</body>
</html>

测试结果:

  没有打印出任何东西

4.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
function Foo() {
console.log(xo);
var xo='武老板';
}
Foo();
</script>
</body>
</html>

结果:

没有打印出任何东西

5.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
var name='alex';
function Foo() {
this.name='武老板';
this.func=function () {
alert(this.name);
}
}
var obj=new Foo();
obj.func()
</script>
</body>
</html>

结果:

弹框

前端部分面试题目整理_html_02

6.重点题目(详细了解that和this的区别)

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
var name='alex';
function Foo() {
this.name='武老板';
this.func=function () {
     //注意这里是自执行函数,这里的this指的是上边的function结果自然是alex了 
(function() {
alert(this.name);
})()
}
}

var obj=new Foo();
obj.func()
</script>
</body>
</html>

结果:

前端部分面试题目整理_javascript_03

 



标签:function,题目,name,Title,前端,面试,func,var,xo
From: https://blog.51cto.com/u_11182673/5848899

相关文章