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

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Feb 21, 2021 in Java by dante07 (13.1k points)
0 votes
1 answer

Browse Categories

...