You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The toString () method is invoked first when the date object is converted to a basic type. and Object calls toString () first when converted to a string
forexample one:
let date = new Date()
console.log(date.toString()); //Sun Dec 09 2018 16:48:43 GMT+0800 (中国标准时间)
console.log(date.valueOf()); //1544345323377
console.log(date + '5'); //Sun Dec 09 2018 16:48:43 GMT+0800 (中国标准时间)4
forexample two:
let date = {name: 'yjh'}
console.log(date.toString()); //[object Object]
console.log(date.valueOf()); //{name: "yjh"}
console.log(date + '5'); //[object Object]5
Your mistake:
对象在转换基本类型时,首先会调用 valueOf 然后调用 toString。
The text was updated successfully, but these errors were encountered:
The toString () method is invoked first when the date object is converted to a basic type. and Object calls toString () first when converted to a string
forexample one:
let date = new Date()
console.log(date.toString()); //Sun Dec 09 2018 16:48:43 GMT+0800 (中国标准时间)
console.log(date.valueOf()); //1544345323377
forexample two:
let date = {name: 'yjh'}
console.log(date.toString()); //[object Object]
console.log(date.valueOf()); //{name: "yjh"}
Your mistake:
对象在转换基本类型时,首先会调用 valueOf 然后调用 toString。
The text was updated successfully, but these errors were encountered: