Organizational Research By

Surprising Reserch Topic

why does instanceof return false for some literals


why does instanceof return false for some literals  using -'javascript,literals,instanceof'

"foo" instanceof String //=> false
"foo" instanceof Object //=> false
true instanceof Boolean //=> false
true instanceof Object //=> false
false instanceof Boolean //=> false
false instanceof Object //=> false

// the tests against Object really don't make sense


Array literals and Object literals match...

[0,1] instanceof Array //=> true
{0:1} instanceof Object //=> true


Why don't all of them? Or, why don't none of them?
And, what are they an instance of, then? Nothing()?

It's the same in FF3, IE7, Opera, and Chrome. So, at least it's consistent. ;)



Missed a few. ;)

12.21 instanceof Number //=> false
/foo/ instanceof RegExp //=> true

    

asked Sep 16, 2015 by akhilesh
0 votes
1 view



Related Hot Questions

6 Answers

0 votes
NULL
answered Sep 16, 2015 by ashishshukla
0 votes
NULL
answered Sep 16, 2015 by dahiyabecomp
0 votes
NULL
answered Sep 16, 2015 by patilkiran.101
0 votes
NULL
answered Sep 16, 2015 by bhavin
0 votes
NULL
answered Sep 16, 2015 by deepak07.s
0 votes
NULL
answered Sep 16, 2015 by pradip.bhoge

...