DEV Community

Cover image for The new Keyword in JavaScript
Bhupesh Chandra Joshi
Bhupesh Chandra Joshi

Posted on

The new Keyword in JavaScript

What the new keyword does?
New Keyword in JavaScript is a way to create object by intializing the object constructor. Let's visit blog practically, we can create , give name to objects and assign the properties to the object(your old friend- properties are just like jeans, belt ,shirt and you can assign a wearing Cloths function.)

let girlFriend=null; // null because I don't have girlfriend.

Constructor functions
why I have created small letter of assignProperty(girlfriend) function signature? Before jumping into this, let's visit what is constructor frist? constructor is a sepecial function that can initialize the object or adds values to key of an object. This time we will create new girlfriend / girlfriend should only one, but don't mind ,it's just a program and we will initilize ,girlfriend's properties here.

Object creation process

We have two ways Object creation , the first will be object literal and second way we have discussed first. The object constuctor initialization.

let student={};

// This is a way , and considered the best practice to create an object.

How new links prototypes

If you will be observe it clearly that prototype is just an object, that inherited from your in built constuctor from object class that provides the information about constructor. when you add a functionName.prototype.fullName="New function full name will be added";

Instances created from constructors

When we create a instance then we will inherit from Object.prototype, and even javaScript has ways to prevent prototype creation.

1-Object.create(null)
2-Object.freeze(Object.prototype)

Top comments (0)