![]() |
VOOZH | about |
In this article, we will understand exactly what the new keyword is, and why we use the new keyword, and how we can use the new keyword.
The new keyword in JavaScript: The new keyword is used to create an instance of a user-defined object type and a constructor function. It is used to construct and returns an object of the constructor function.
Syntax:
new constructor[([arguments])]
Why do we use the new keyword in JavaScript?
These are the following features to use the new keyword:
Example 1: In the below example, we will create a message function to print names with greetings and we will create an instance of message function.
Output: Output on console
Hey Vikash
Example 2: In the below example, we will create a student function and create an instance of the function using the new keyword as shown below.
Output:
Vikash 22