js Date 与 new Date() 的区别

Date() 与 new Date() 返回的内容一样,只是格式不一样,Date()返回的是字符串,new Date()返回的是 时间对象。 因此,
new Date() 可以使用 Date 对象的属性和方法。

js Date 与 new Date的区别图片
Date 与 new Date() 的区别
var a = Date();
var b = new Date();

console.log('a>Date>', a)
console.log('a>Date>typeof>', typeof a)


console.log('b>Date>', b)
console.log('b>Date>typeof>', typeof b)
console.log('b>Date>instanceof>', b instanceof Date)

猜你喜欢

转载自blog.csdn.net/qq_33650655/article/details/91535092