Advertisement

这些前端大厂面试题你会做吗?每日10题大厂面试题(八)

阅读量:

文章目录

  • 题1(模版字符串)
  • 题2(引用复制)
  • 题3(Delete)
  • 题4(yield)
  • 题8(扩展运算符)
  • 题10(箭头函数)

题1(模版字符串)

下面代码输出的是

复制代码
    function getPersonInfo(one, two, three) {
    	console.log(one);
    	console.log(two);
    	console.log(three);
    }
    const person = 'Lydia';
    const age = 21;
    getPersonInfo`${person} is ${age} years old`
    
    
      
      
      
      
      
      
      
      
    
    代码解读

答案:["", “is”, “years old”] Lydia 21
这道题主要考察:

*模版字符串:当采用标记型模版字符串时,则第一个自变量始终由一个由多字符组成的数组构成。其余自变量则取自嵌入在模版字符串中的任意表达式之结果!

题2(引用复制)

下面代码输出的是

复制代码
    let person = {name: 'Lydia'}
    const members = [person]
    person = null
    
    console.log(member)
    
    
      
      
      
      
      
    
    代码解读

答案:[null]
这道题主要考察:

引用机制:当两个对象被设定为相等时,在内存中它们会共享相同的引用空间以实现互动关系。然而,在将引用从一个变量传递给另一个变量的过程中,并未真正执行复制行为

题3(Delete)

下面代码输出的是

复制代码
    Dog.prototype.bark = function () {
    	console.log('Woof I am ${this.name}`);
    };
    
    const pet = new Dog('Mara');
    pet.bark();
    delete Dog.prototype.bark;
    pet.bark();
    
    
      
      
      
      
      
      
      
      
    
    代码解读

答案:“Woof I am Mara", TypeError
这道题主要考察:

  • Through the use of the delete keyword, an object's property can be removed, and this operation is also applicable to its prototype. After erasing a property from the prototype, such a property will no longer be accessible on the prototype chain. When attempting to invoke a non-existent function, a TypeError exception will be thrown.

题4(yield)

如何能打印出console.log语句后注释掉的值

复制代码
    function* startGame() {
    	const answer = yield 'Do you love Javscript';
    	if (answer !== 'Yes') {
    		return 'oh wow... Guess we are gone here'
    	}
    	return 'Javascript loves you back';
    }
    const game = startGame();
    console.log(); // Do you love Javascript
    console.log(); // Javascript loves you back
    
    
      
      
      
      
      
      
      
      
      
      
    
    代码解读

答案:game.next().value and game.next(‘Yes’).value
这道题主要考察:

在 yield: next 方法中可以接受一个变量,在此之后传递给前一个 yield 表达式作为其返回值。

题8(扩展运算符)

下面输出的是

复制代码
    [...'lydia']
    
    
      
    
    代码解读

答案:[‘l’, ‘y’, ‘d’, ‘i’, ‘a’]
这道题主要考察:

扩展运算符:字符串作为可迭代对象存在。展开操作符会将每个可迭代字符一一对应地转换为独立元素

题10(箭头函数)

下面输出的是

复制代码
    const shape = {
    	radius: 10, 
    	diameter() {
    		return this.radius * 2;
    	}, 
    	perimeter: () => 2 * Math.PI * this.radius
    };
    shape.diameter():
    shape.perimeter();
    
    
      
      
      
      
      
      
      
      
      
    
    代码解读

答案:20 and NaN
这道题主要考察:

在arrow functions中:... this keyword points to its surrounding context, differing from ordinary functions in that when we call perimeter, it does not point to the shape object but rather refers to the context it was defined in.

今天的分享到这里啦!如果你觉得这篇文章对你有帮助,请不妨转发给需要的人,在评论区留下你的看法并收藏起来备用哦!点赞支持一下也是对作者最大的鼓励!

在这里插入图片描述

全部评论 (0)

还没有任何评论哟~