A wrapper class

Number(), String(), and Boolean() are “wrapper classes” for numbers, strings, and Booleans (which must be primitives), respectively.

The PrimitiveValue property of Number(), String(), and Boolean(), all of which are PrimitiveValue, stores their PrimitiveValue values and cannot be invoked

The primitive type value that comes out of new can participate in the operation normally

Many programming languages have “wrapper classes” designed so that primitive type values can get methods from their constructor’s Prototype.

 <script>
        var a = new Number(123);
        var b = new String(Mooc Network);
        var c = new Boolean(true);

        console.log(a);
        console.log(typeof a);    //object
        console.log(b);
        console.log(typeof b);     //object
        console.log(c);
        console.log(typeof c);     //object

        console.log(5 + a);     / / 128
        console.log(b.slice(1.2));  / / 'class'
        console.log(c && true);   //true

        var d = 123;
        console.log(d.__proto__ == Number.prototype); //true

        var e = Mooc Network;
        console.log(e.__proto__ == String.prototype);   //true

        console.log(String.prototype.hasOwnProperty('toLowerCase'));  //true
        console.log(String.prototype.hasOwnProperty('slice'));   //true
        console.log(String.prototype.hasOwnProperty('substr'));   //true
        console.log(String.prototype.hasOwnProperty('substring'));  //true

        console.log(String.prototype);
    </script>
Copy the code