In js, what method is called when the date and number types are compared with =?

normally, when comparing object and number types, the valueOf method will be called first. If the return value is not the original type, the toString method will be called. If the return value is not the original type, an error will be reported.

but I tested the date object, and that doesn"t seem to be the case.

clipboard.png

I compare the return value of valueOf, which is false, but when I rewrite the toString and valueOf methods, the comparison will be the same as other object types, reporting an error.

so I would like to ask, which method is called first when comparing number and date types?

Sep.30,2021
Menu