Javascript Concatenation -


this question has answer here:

i came across following snippet of codes in javascript quiz online. not understand how concatenation works in js. can 1 explain how works ?

[] + [] = ""    // output : ""  [] + [] + "foo" // output : "foo" 

javascript tries apply + operator in different ways, it's been taught to.

so unless explicitly told, calls tostring method of array it's best guess when it's told add 2 arrays.

[] + [] = ""  +[] + [] = "0"    // if give hint cast 1 of array number  +[] + +[] = 0     // if give hint cast both arrays number 

while [] + [] + "foo"

([] + []) + "foo" = "" + "foo" = "foo" 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -