first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

JavaScript: “Why does instanceof return false for some literals?”; stackoverflow.com

"foo" instanceof String //=> false "foo" instanceof Object //=> false true instanceof Boolean //=> false true instanceof Object //=> false false instanceof Boolean //=> false false instanceof Object //=> false [0,1] instanceof Array //=> true {0:1} instanceof Object //=> true 12.21 instanceof Number //=> false /foo/ instanceof RegExp //=> true

That’s because those things are primitives, and unless they need to be used as objects (when you are calling methods on them, for example) they remain so. The only time they “become” objects is when they need to be wrapped. If you are familiar with the concept of “boxing” in .NET, then think of it in that way.

[http://stackoverflow.com/questions/203739/why-does-instanceof-return-false-for-some-literals]

mod date: 2010-03-02T22:41:39.000Z