How to create JavaScript objects using new operator?


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.

Updated on: 16-Jun-2020

211 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements