[] is an array instance, but "" is not a string

Possible duplicate:
Why does instanceof return false for some literals?

If I...

[] instanceof Array;

... it returns true, although I have not used new Array().

But if I ...

"" instanceof String;

... it returns falsebecause I have not used new String().

Why? I understand that []- this is a language construct for creating arrays, and ""- this is a language construct for creating strings. Therefore, I do not understand why one returns trueand the other returns false.

In addition, all of the following codes return true:

[] instanceof Array; /* true */
Array() instanceof Array; /* true */
new Array() instanceof Array; /* true */

But with the lines:

"" instanceof String; /* false */
String() instanceof String; /* false */
new String() instanceof String; /* true */

Is it worth it to String() instanceof Stringreturn true?

Edit:

( ): , ?

+2

All Articles