Why does calling a property on a string not give an error?

Jim

In JavaScript why does the second line below return undefined and not an error?

var apple = 'apple';
apple.colour; //undefined
Pointy

An expression that evaluates to a primitive value that appears on the left side of a . or [] operator will be automatically "wrapped" in an object of the appropriate type (String, Number, Boolean).

Thus

"hello".length

is evaluated as if it were

new String("hello").length

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why does calling a JPanel from other class give NullPointerException error?

Why does String.Format give inputString not formatted error for this String

Why does std::atomic<std::string> give trivially copyable error?

Why does moving the string variable give error here?

Why does "!!" not give a compilation error?

Why does this conversion give an error?

Why does camel route give Failed to send reply with payload error after calling the Message Consumption Listener?

Why does calling `system` with indirect object give syntax error only with autodie

why does the "overflow" property give the different result?

Why does IE give this error: Object doesn't support property or method isNaN

Why does it give an error 'searchInput' of undefined

Why does Laravel give error in SQL query?

Why does maven install give this error with npm?

Why does the for loop give an error in bubble sort?

Why does the compiler not give an error for this addition operation?

Why does this SFINAE give an error in gcc?

Why does this program give an error when run

Why does "tasksel" give an "aptitude failed" error?

Why does this Boolean statement in Ruby give an error?

Why does "const extern" give an error?

Why does double 'COPY' in dockerfile give error

Why does anonymous namespace give redefinition error?

Why does this VBA index statement give an error?

Why does this SQL query give a syntax error?

Why does this piece of code not give error?

Why does Agda give error "expected: ℕ, actual: ℕ"

Why does '->'(12, b) give an error?

Why printf("test"); does not give any error?

Why does 160*1440 give an overflow error?