Comment on Stupid LanguagesparentComments−adam-f13yNeither.But for the sake of argument, I'd rather see ['10','10','10','10'].map(Number);−camus13y['10','10','10','10'].map(Number);this is one is correct['10','10','10','10'].map(String);this one makes sense['10','10','10','10'].map(Object);i'd like somebody to explain me this one ?????????Javascript is really difficult as soon as one try to do non trivial stuffs.−ricardobeat13yObject('abc') is the same as new String('abc'), Object(1) the same as new Number(1) - it just calls the .constructor−iso-8859-113ybut "new Number(x)" is not equal to "Number(x)". So, it's tricky, I guess?−ville13yNumber(x) performs a type conversion to number, new Number(x) constructs a primitive wrapper object Number: typeof Number("10") //=> "number" typeof new Number("10") //=> "object" The same applies to other wrapper objects, that is, Boolean and String.
Comments
Neither.
But for the sake of argument, I'd rather see
['10','10','10','10'].map(Number);
this is one is correct
['10','10','10','10'].map(String);
this one makes sense
['10','10','10','10'].map(Object);
i'd like somebody to explain me this one ?????????
Javascript is really difficult as soon as one try to do non trivial stuffs.
Object('abc') is the same as new String('abc'), Object(1) the same as new Number(1) - it just calls the .constructor
but "new Number(x)" is not equal to "Number(x)". So, it's tricky, I guess?
Number(x) performs a type conversion to number, new Number(x) constructs a primitive wrapper object Number:
The same applies to other wrapper objects, that is, Boolean and String.