Why does javascript prefers to return a String
over any other choices ?
Consider the following snippet.
var arr = [\'Hello1\', \'Hello2\', \
The statement
return this[x] || null || 'aïe' || 12 || undefined ;
will evaluate the subexpressions left to right, and will return the first subexpression that does not evaluate to false. The non-existent element evaluates to false as it's undefined, and null
is false by definition. That leaves the string as the first non-false subexpression, so that's what you get.