Sometimes it’s good to remind the basics.
Today, I was trying to test if a Date
object that I made becoming a string using toISOString()
was a string.
And I immediately thought about if(date instanceof String)
but this was always false
…
And then I found this post: http://stackoverflow.com/a/21605936
It was painful to see how sometimes you forget that Javascript can be crap and you need a basic reminder.
I created a little JSFiddle to show exactly what I wanted to do and to make obvious the difference between literals and objects. But you can also see the code just here:
Finally, another link you might find useful on the Literals Vs Objects topic: http://stackoverflow.com/questions/203739/why-does-instanceof-return-false-for-some-literals