Please explain why and how +new Date(); works as 'workaround' for Date.now() in IE8 or below

后端 未结 3 1114
眼角桃花
眼角桃花 2021-01-30 21:35

(I\'m reading the book \"Professional JavaScript for Web Developers\" to give a context about this question, specifically Chapter 5 on Reference Types)

I\'m wo

3条回答
  •  盖世英雄少女心
    2021-01-30 21:45

    The unary + operator converts a value to a number. For example +"123" will convert the string "123" to the number 123. This will also work for a date, and the date converted to a number gives the number of milliseconds.

提交回复
热议问题