Posts

Showing posts from May, 2024

JavaScript Interview Questions

What are the possible ways to create objects in JavaScript There are many ways to create objects in javascript as mentioned below: Object literal syntax: The object literal syntax (or object initializer), is a comma-separated set of name-value pairs wrapped in curly braces. var object = { name : "Amit" , age : 40 } ; Object literal property values can be of any data type, including array, function, and nested object. Note:  This is one of the easiest ways to create an object. Object constructor: The simplest way to create an empty object is using the  Object  constructor. Currently this approach is not recommended. var object = new Object ( ) ; The  Object()  is a built-in constructor function so "new" keyword is not required. The above code snippet can be re-written as: var object = Object ( ) ; Object's create method: The  create  method of Object is used to create a new object by passing the specificied prototype object and p...