Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

The new keyword in JavaScript can be quite confusing when it is first encountered, as people tend to think that JavaScript is not an object-oriented programming language.

  • What is it?

  • What problems does it solve?

  • When is it appropriate and when not?

1 Answer

0 votes
by (106k points)
  1. The new keyword in JavaScript creates a new object. The type of this object simply objects.

  2. Also, it makes this variable point to the newly created object.

  3. New keyword executes the constructor function, using the newly created object whenever this is mentioned.

See the code below to understand new keywords practical uses:-

function Foo() { 

return this; 

var a = Foo(); 

var b = new Foo();

a instanceof Window; 

a instanceof Foo; 

instanceof Window; 

b instanceof Foo; 

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...