Use Object constructor acts as a factory method for primitive data types in JavaScript

Description

The following code shows how to use Object constructor acts as a factory method for primitive data types.

Example


<!--  w  w w.j a v a  2  s. c om-->
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
var obj1 = new Object("some text");
document.writeln(obj1 instanceof String); //true

var obj2 = new Object(213);
document.writeln(obj2 instanceof Number); //true

var obj3 = new Object(true);
document.writeln(obj3 instanceof Boolean); //true
</script>
</head>
<body>
</body>
</html>

Click to view the demo

The code above generates the following result.

Use Object constructor acts as a factory method for primitive data types in JavaScript