what is the purpose of numeric/boolean/string objects as opposed to primitive values?

Posted by zespri on Stack Overflow See other posts from Stack Overflow or by zespri
Published on 2010-06-14T08:57:30Z Indexed on 2010/06/14 9:02 UTC
Read the original article Hit count: 148

Filed under:
|

In javascript you can call a function as a function or as a constructor. For example you can do :

myObject = new Number(13);
myPrimitiveValue = Number(13);

or simply

myPrimitiveValue = 13;

I understand the difference between the results. Can you explain me under which reasonable circumstances creating a number, a boolean or a string as an object is desirable? For example, ability to set new properties (this is something you can do on objects but can't really do on primitive values) is almost always a bad idea for objects containing number/boolean/string. Why would I want a numeric/boolean/string object?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about ecmascript