How to create JavaScript objects using new operator?

JavascriptWeb DevelopmentFront End Technology

The new keyword in JavaScript is the new operator, which creates an instance of a user-defined object type.

Example

You can try to run the following code to create JavaScript objects using new operator −

Live Demo

<!DOCTYPE html>
<html>
   <body>
      <p id = "test"></p>
      <script>
         var dept = new Object();
         dept.employee = "Amit";
         dept.department = "Technical";
         dept.technology ="Java";

         document.getElementById("test").innerHTML =
         dept.employee + " is working on " + dept.technology + " technology.";
      </script>
   </body>
</html>

Output

Amit is working on Java technology.
raja
Published on 03-Feb-2018 11:11:14
Advertisements