
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
What is the 'new' keyword in JavaScript to create an object and how to access values?
The new keyword creates an object in JavaScript. To access values, use the dot notation. Following is the code −
Example
function newObjectCreation() { this.firstName = "John"; } var newObject = new newObjectCreation(); newObject.firstName="David"; console.log("The first name="+newObject.firstName);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo134.js
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo134.js The first name=David
- Related Articles
- How to create an object and access its properties in JavaScript?
- How to access an object through another object in JavaScript?
- What is an object in JavaScript and access any property ?**
- What is the 'new' keyword in JavaScript?
- How to access 'this' keyword inside an arrow function in JavaScript?
- Does static factory method internally use new keyword to create object in java?
- How to access the first value of an object using JavaScript?
- How to access an object value using variable key in JavaScript?
- How to get the values of an object in JavaScript?
- How to access an object having spaces in the object’s key using JavaScript?
- How to create an object with prototype in JavaScript?
- How to add, access JavaScript object methods?
- How to create a new object and get its saved object in MongoDB?
- What is the difference between `new Object()` and object literal notation in JavaScript?
- How to create a new object from the specified object, where all the keys are in lowercase in JavaScript?

Advertisements