Syntax error How to create JavaScript objects using new operator?

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: 2020-06-16T13:39:41+05:30

318 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements