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
Post a Comment