JS Coding Questions Logo
JS Coding Questions
#133💼 Interview💻 Code

How do you compare two date objects

Advertisement

728x90

You need to use date.getTime() method in order to compare unix timestamp values

javascript
1var d1 = new Date();
2
3var d2 = new Date(d1);
4
5console.log(d1.getTime() === d2.getTime()); //True
6
7console.log(d1 === d2); // False

Advertisement

Responsive Ad
🎯 Practice NowRelated Challenge

JavaScript Coding Exercise 49

Test your knowledge with this interactive coding challenge.

Start Coding

Advertisement

728x90
133of476