某科技公司 前端一面笔试题1-3年

183 阅读1分钟
 async function async1(){
     console.log('async1 start');
     await async2();
     console.log('async1 end')
 }
 ​
 async function async2(){
     console.log('async2')
 }
 ​
 console.log('script start');
 ​
 setTimeout(() => {
     console.log('setTimeout')
 }, 0);
 ​
 async1();
 ​
 new Promise((resolve) => {
     console.log('promise1');
     resolve();
 }).then(() => {
     console.log("promise2");
 }).then(() => {
     console.log("promise2_then")
 });
 ​
 ​
 // script start
 // async1 start
 // async2
 // promise1
 // async1 end
 // promise2
 // promise2_then
 // setTimeout
 function Foo() {
   Foo.a = function () {
     console.log(1)
   }
   this.a = function () {
     console.log(2)
   }
 }
 ​
 Foo.prototype.a = function () {
   console.log(3)
 }
 ​
 Foo.a = function () {
   console.log(4)
 }
 ​
 Foo.a() 
 let obj = new Foo()
 obj.a() 
 Foo.a() 
 ​
 // 4 2 1
 // b, b
 let a = 111,
   b = '111'
 ​
 // a, b
 let a = Symbol('111'),
   b = Symbol('111')
 ​
 // b, b
 let a = { key: '111' },
   b = { key: '222' }
 ​
 let c = {
   [a]: 'a',
   [b]: 'b'
 }
 ​
 console.log(c[a], c[b])
 const obj = {
   1: '2',
   2: '3',
   length: 2,
   push: Array.prototype.push,
   slice: Array.prototype.slice
 }
 ​
 obj.push(4)
 obj.push(5)
 ​
 console.log(obj)
 // {
 //     '1': '2',
 //     '2': 4,
 //     '3': 5,
 //     length: 4,
 //     push: [Function: push],
 //     slice: [Function: slice]
 // }
 function fn(o) {
   o.url = 'https://www.baidu.com'
   o = new Object()
   o.url = 'https://www.google.com'
 }
 ​
 let o = new Object()
 ​
 o.url = 'https://www.bing.com'
 fn(o)
 ​
 console.log(o.url) // https://www.baidu.com
 ​