Why does javascript prefers to return a String
over any other choices ?
Consider the following snippet.
var arr = ['Hello1', 'Hello2', 'Hello3'];
Array.prototype.item = function(x) {
return this[x] || null || 'aïe' || 12 || undefined ;
};
console.log( arr.item(43) ); // returns aïe
I intentionally called a non-existent array element.
However i cannot understand why does arr.item(43)
returns the String
? Why not null
or undefined
or even 12
?