What does the new keyword do in JavaScript

0 votes
Can you tell me with proper code explanation that What does the new keyword do in JavaScript?
Jan 10 in Java-Script by Ashutosh
• 17,360 points
53 views

1 answer to this question.

0 votes

In JavaScript, the new keyword is used to create an instance of a constructor function or class. Here's how it works:

  1. It creates a new, empty object.

  2. It sets the prototype of the new object. The new object's __proto__ property is linked to the constructor function's prototype property, establishing the inheritance chain. This allows the new object to access properties and methods from the prototype.

  3. It binds this to the new object. Inside the constructor function, this refers to the newly created object, enabling you to assign properties and methods to it.

  4. It returns the new object. If the constructor function doesn't explicitly return a value, the new object is returned by default.

answered Feb 7 by Navya

Related Questions In Java-Script

0 votes
1 answer

How do you access the matched groups in a JavaScript regular expression?

Hello, Here’s a method you can use to ...READ MORE

answered May 28, 2020 in Java-Script by Niroj
• 82,840 points
2,026 views
0 votes
1 answer

How do I copy to the clipboard in JavaScript?

Hello @kartik, To copy HTML , you can ...READ MORE

answered Aug 28, 2020 in Java-Script by Niroj
• 82,840 points
951 views
0 votes
0 answers

What is the difference between ' and " in JavaScript?

I came across this query and am ...READ MORE

Sep 23, 2022 in Java-Script by Abhinaya
• 1,160 points
737 views
0 votes
0 answers

in java what does the @ symbol mean?

I am aware of what it implies ...READ MORE

Sep 29, 2022 in Java-Script by Abhinaya
• 1,160 points
797 views
0 votes
1 answer

How can I iterate through keys and values in JavaScript?

In JavaScript , you can iterate through ...READ MORE

answered Feb 7 in Java-Script by Navya
59 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP