iugo / blog

https://iugo.github.io/blog
3 stars 0 forks source link

JavaScript Useless Tricks #57

Open iugo opened 3 years ago

iugo commented 3 years ago

BigInt

typeof 1n === 'bigint'
typeof BigInt('1') === 'bigint'
typeof Object(1n) === 'object'

Object(1n) + 2n === 3n
Object(1n) + Object(2n) === 3n

参考: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt

Date

在 Safari 浏览器中, 对 new Date() 比较难理解.

new Date('2020-01-02') // 有效
new Date('2020/01/02') // 有效

new Date('2020-01-02 19:20') // 🚫 Invalid Date
new Date('2020/01/02 19:20') // 有效