Object constructor acts as a factory method for primitive data types

The Object constructor acts as a factory method and is capable of returning an instance of a primitive wrapper based on the type of value passed into the constructor.

For example:

 
<!DOCTYPE html>
<html>
<head>
    <title>Example</title>
    <script type="text/javascript">
        var obj = new Object("some text"); 
        document.writeln(obj instanceof String); //true 
       
    </script>
</head>
<body>
</body>
</html>
  
Click to view the demo
 
<!DOCTYPE html>
<html>
<head>
    <title>Example</title>
    <script type="text/javascript">
    
        var obj = new Object(213); 
        document.writeln(obj instanceof Number); //true 

       
    </script>
</head>
<body>
</body>
</html>
  
Click to view the demo
 
<!DOCTYPE html>
<html>
<head>
    <title>Example</title>
    <script type="text/javascript">
        var obj = new Object(true); 
        document.writeln(obj instanceof Boolean); //true 
       
    </script>
</head>
<body>
</body>
</html>
  
Click to view the demo
Home 
  JavaScript Book 
    Language Basics  

Primitive Wrapper Class:
  1. Primitive wrapper class
  2. Object constructor acts as a factory method for primitive data types
  3. primitive wrapper constructor vs casting function