当点击class为inner的div块时,控制台依次输出结果是什么? 10. 下面程序的输出结果是?
(async () => {console.log(1);setTimeout(() => {console.log(2);}, 0);await new Promise((resolve, reject) => {console.log(3);}).then(() => {console.log(4);});console.log(5);})();
- 下面程序的输出结果是:
setTimeout(() => console.log('a'));Promise.resolve().then(() => console.log('b’); ).then(() => Promise.resolve('c').then((data) => {setTimeout(() => console.log('d'));console.log('f');return data;}) ).then(data =https://www.isolves.com/it/cxkf/qd/2022-02-28/> console.log(data));
- 下面程序的输出结果是:
console.log('one'); setTimeout(function() { console.log('two'); }, 0); Promise.resolve().then(function() { console.log('three'); }) console.log('four');
- 下面程序的执行结果是:
setTimeout(function () {console.log(C)},0)console.log('D')new Promise(function(resolve){console.log('E')resolve()console.log('F')}).then(function() {console.log('G')})console.log('H')
- 有一个输出函数定义如下:
function log(msg, time) {return new Promise((resolve) => {setTimeout(() => {console.log(msg);resolve();}, time);});}
则下面三段代码输出的结果是:// 第一段代码:(async () => {for (let i = 0; i < 5; i++) {await log(i, 1000);}})();
// 第二段代码:(async () => {[ 1, 2, 3, 4 ].forEach(async (i) => {await log(i, 1000);});})();
// 第三段代码:(async () => {for (const i of [ 1, 2, 3, 4 ]) {await log(i, 1000);}})();
原型与原型链关于原型JS:看完这篇文章,彻底了解 “原型” & “this”传送门: 原型与原型链题目解析[4]
- 下面程序的输出结果依次是?
function Fn1(name) {if(name){this.name = name;}}Fn1.prototype.name="jack"let a = new Fn1();console.log('a:', a.name);function Fn2(name) {this.name = name;}Fn2.prototype.name="jack"let b = new Fn2();console.log('b:', b.name);
- 下面程序的输出结果是?
var Foo = (function() {var x = 0;function Foo() {}Foo.prototype.increment = function() {++x;console.log(x);};return Foo;})(); var a = new Foo();a.increment();a.increment();var b = new Foo();a.increment();
- 下面程序的输出结果是?
var name = 'Jay'function Person(name){this.name = name;console.log(this.name)}var a = Person('Tom')console.log(name)console.log(a)var b = new Person('Michael')console.log(b)
- 请表述以下代码的执行结果和原因
class A{}class B extends A{}const a = new A()const b = new B()a.__proto__b.__proto__B. __proto__B. prototype.__proto__b.__proto__.__proto__
- 请表述以下代码的执行结果和原因
function test() {getName = function() {Promise.resolve().then(() => console.log(0));console.log(1);};return this; }test.getName = function() {setTimeout(() => console.log(2), 0);console.log(3);};test.prototype.getName = function() {console.log(4); };var getName = function() {console.log(5);};function getName() {console.log(6); }test.getName(); getName(); test().getName(); getName();new test.getName();new test().getName();new new test().getName();
- 请表述以下代码的执行结果和原因
var tmp = {};var A = function() {};A. prototype = tmp;var a = new A();A. prototype = {};var b = Object.create(tmp);b.constructor = A. constructor;console.log(a instanceof A);console.log(b instanceof A);
- 下面程序的执行结果是:
function Foo(){}Foo.prototype.z = 3;var obj = new Foo();console.info(obj.z)obj.z = 10;console.info(obj.z);delete obj.z;console.info(obj.z);
- 下面程序的执行结果是:
const Book = {price: 32}const book = Object.create(Book);book.type = 'Math';delete book.price;delete book.type;console.log(book.price);console.log(book.type);
作用域与预编译- 下面的程序会报错吗?如果不会,输出结果分别是多少?
function sayHello() {console.log(name);console.log(age);var name = "Tom";let age = 18;} sayHello();