Built-in javascript constructors?


Javascript has provided some built-in constructors. Those built-in functions include object(), string(), number, etc. We cannot include Math object in those built-in constructors because Math is a global object. The 'new' keyword cannot be used with Math.

Example

In the following example, many built-in constructors were used and their types were displayed as shown in the output.

Live Demo

<html>
<body>
<script>
   var a = new Object();
   var b = new String();
   var c = new Number();
   var d = new Boolean();
   var e = new Array();
   var f = new RegExp();
   document.write(
      "a: " + typeof a + "</br>" +
      "b: " + typeof b + "</br>" +
      "c: " + typeof c + "</br>" +
      "d: " + typeof d + "</br>" +
      "e: " + typeof e + "</br>" +
      "f: " + typeof f + "</br>" 
   );
</script>
</body>
</html>

Output

a: object
b: object
c: object
d: object
e: object
f: object
raja
Published on 07-Aug-2019 13:48:16
Advertisements