JS从基础到进阶,看看和你的认知一样吗???

JS从基础到进阶,看看和你的认知一样吗???

下面看几个例子,猜猜输出是什么?

提示:注意每题的标题呦!!!

1.this指向

const shape = {
  radius: 10,
  diameter() {
    return this.radius * 2
  },
  perimeter: () => 2 * Math.PI * this.radius
}
shape.diameter()
shape.perimeter()
  • A: 20 and 62.83185307179586
  • B: 20 and NaN
  • C: 20 and 63
  • D: NaN and 63

2.操作符运算

console.log( +true );
console.log( !"Lydia" );
  • A: 1 and false
  • B: false and NaN
  • C: false and false

3.语法运行

function bark() {
  console.log('Woof!')
}
bark.animal = 'dog'
  • A: 正常运行!
  • B: SyntaxError. 你不能通过这种方式给函数增加属性。
  • C: undefined
  • D: ReferenceError

4.数据类型定义

const obj = { 1: 'a', 2: 'b', 3: 'c' }
const set = new Set([1, 2, 3, 4, 5])
console.log( 
	obj.hasOwnProperty('1'), 
	obj.hasOwnProperty(1),
	set.has('1'), 
	set.has(1) 
);
  • A: false true false true
  • B: false true true true
  • C: true true false true
  • D: true true true true

5.数据类型转换

const a = {};
const b = { key: 'b' };
const c = { key: 'c' };
a[b] = 123;
a[c] = 456;
console.log(a[b])

A: 123
B: 456
C: undefined
D: ReferenceError

    各题答案:B、A、A、C、B,看看你都答对了吗?
    补充一下,JS 全局执行上下文,做了两件事即:全局对象和 this 关键字。
    这些题目的参考与出处是来自于一个非常好的github项目,如果想了解学习更多的js进阶问题,请前往JavaScript 进阶问题列表进行查看或者下载。
    今天的分享到此结束,希望对您有所帮助,如果文章有错误或者有什么相关的建议,请直接私信联系我,谢谢!!!此外你如果感觉喜欢请点击进行关注,以后会不定时的分享学习心得,敬请期待(* ̄︶ ̄)(* ̄︶ ̄)(* ̄︶ ̄)

——来自一个程序猿小白的自我成长 && 学习分享

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值