Will try to be brief, so it might not be clear unless you are experienced, will add more references at the end to make things clearer and maybe revise this subject later… - Time is a very limited resource nowadays.
How I got into this conclusion?
instanceof works is not clear to most developers:
typeof [1, 2] // 'object'
typeof null // 'object'
typeof 'foo' // 'string'
typeof new String('foo') // 'object'
'foo' instanceof String // false
new String('foo') instanceof String // true
new String('foo') instanceof Object // true
And things gets way more complicated when you have objects that come from different documents/frames/workers (they are created using different constructors, so
instanceof doesn’t work)… So because of that I started to avoid
instanceof and ended up realizing how cleaner the code becomes when you avoid type checking.
PS: I know that we can use
Object.prototype.toString.call() for type checking, I’m mainly saying that most type checks are a bad idea, doesn’t matter what is the implementation.