Skip to content

String Number and Boolean

Jing Lu edited this page May 13, 2013 · 5 revisions

The internal function String, Number and Boolean are the wrapper object constructors of primitive data.

String(...)        // convert anything to string
new String(...)    // construct a wrapper object of string

One is string and another one is object, that can be verified by typeof keyword:

var str = String(10);
var str2 = new String(10);

debug.assert( typeof str == 'string' );        // str is string
debug.assert( typeof str2 == 'object' );       // str2 is object

But in anytime, you may use valueOf method convert a wrapper object into its primitive data:

var str = str2.valueOf();
debug.assert( typeof str == 'string' );

Number and Boolean are the same as String.