var a = 5; function test() {a = 0;alert(a);alert(this.a);var a;alert(a); }new test();
- 下列程序的输出结果是多少?为什么?
function fun () {return () => {return () => {return () => {console.log(this.name)}}}}var f = fun.call({name: 'foo'})var t1 = f.call({name: 'bar'})()()var t2 = f().call({name: 'baz'})()var t3 = f()().call({name: 'qux'})
- 执行以下代码,输出结果分别是多少?
let obj1 = {a: 1,foo: () => {console.log(this.a)}}// log1obj1.foo()const obj2 = obj1.foo// log2obj2()
- 下面程序的输出结果是什么?为什么?
const Person = (name="wang",age=10) => {this.name = name;this.age = age;return this.name +' is '+ this.age + 'years old'}let result = new Person('zhang',11)console.log(result)
- 请表述以下代码的执行结果和原因
var person = {age: 18,getAge: function() {return this.age;}};var getAge = person.getAgegetAge()
- 请按顺序写出打印结果,并说明原因 。
var name = 'global';var obj = {name: 'local',foo: function(){this.name = 'foo';}.bind(window)};var bar = new obj.foo();setTimeout(function() {console.log(window.name);}, 0);console.log(bar.name); var bar3 = bar2 = bar;bar2.name = 'foo2';console.log(bar3.name);
- 下面程序的执行结果是:
var obj = {name:"zhangsan",sayName:function(){console.info(this.name);}}var wfunc = obj.sayName;obj.sayName();wfunc();var name = "lisi";obj.sayName();wfunc();
- 下面程序的输出结果是:
var name='test' var a = {name: 'ass',getName: function() {return this.name;} } var b = a.getName; b();
事件循环- 下列程序的输出结果分别是多少?为什么?
const promiseA = Promise.resolve('a')promiseA. then((res) => {console.log(res)}).then((res) => {console.log(res)})const promiseB = Promise.resolve('b')promiseB. then((res) => {console.log(res)})promiseB. then((res) => {console.log(res)})
- 下面程序的输出结果依次是多少?
setTimeout(() => {console.log(1)}, 0)const P = new Promise((resolve, reject) => {console.log(2)setTimeout(() => {resolve()console.log(3)}, 0)})P.then(() => {console.log(4)})console.log(5)
- 下面程序的输出结果是
setTimeout(function(){console.log(1);}, 0)new Promise(function(resolve){console.log(2);resolve();console.log(3);}).then(function(){console.log(4);})console.log(5);
- 下面程序的输出结果是?
(async () => {console.log(1);setTimeout(() => {console.log(2);}, 0);await new Promise((resolve, reject) => {console.log(3);}).then(() => {console.log(4);});console.log(5);})();
- 下面程序的输出结果是:
new Promise((resolve) => {console.log('1')resolve()console.log('2')}).then(() => {console.log('3')})setTimeout(() => {console.log('4')})console.log('5')
- 下面程序的输出结果是:
var p1 = new Promise(function(resolve, reject){resolve("2")})setTimeout(function(){console.log("1")},10)p1.then(function(value){console.log(value)})setTimeout(function(){console.log("3")},0)
- 下面程序的输出结果是:
setTimeout(function() {console.log('setTimeout');}, 0);Promise.resolve().then(function() {console.log('promise1');}).then(function() {console.log('promise2');});
- 请表述以下代码的执行结果和原因
setTimeout(function() {console.log(1)},0)new Promise(function executor(resolve){console.log(2)for (var i = 0; i<10000; i++) {i - 9999 && resolve()}console.log(3)}).then(function() {console.log(4)})console.log(5)
- 在网页中有两个div块,html代码如下
<div class="outer"> <div class="inner"></div></div>
对应的js代码如下:var outer = document.querySelector('.outer');var inner = document.querySelector('.inner');function onClick() {console.log('click');setTimeout(function() {console.log('timeout');}, 0);Promise.resolve().then(function() {console.log('promise');});outer.setAttribute('data-random', Math.random());}inner.addEventListener('click', onClick);outer.addEventListener('click', onClick);
推荐阅读
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 移动前端开发和 Web 前端开发的区别是什么?
- 当下最火的前端面试题,回溯算法来了
- php大文件切片上传
- 轻量、高效、功能强大的微前端框架-MicroApp
- 前端领域如何实现请求中断
- 前端开发之动态管理Nginx集群的方法
- 5 个网站将您的前端技能提升 100 倍
- 文档如何自动化部署到线上环境「每个前端都可以拥有自己的博客」
- 前端开发干货:让 iframe 焕发新生开发
- 前端新手必备常用JavaScript方法函数大全