Tuesday, November 19, 2024
Google search engine
HomeLanguagesJavascriptJavaScript Object Reference

JavaScript Object Reference

JavaScript Objects are the most important data type and form the building blocks for modern JavaScript. The “Object” class represents the JavaScript data types. Objects are quite different from JavaScript’s primitive data types (Number, String, Boolean, null, undefined, and symbol). It is used to store different types of key collections and complex entities. It can be created by using the Object() method or by using object initializer/literal syntax.

Syntax:

objectName.methodName()

Example:  Using function definition as property value and accessing with additional details. 

Javascript




// Object creation
let student = {
    name: "Martin",
    class: "12th",
    section: "A",
  
    studentDetails: function () {
        return this.name + " " + this.class
            + " " + this.section + " ";
    }
};
  
// Display object data
console.log("STUDENT " + student.studentDetails());


Output:

STUDENT Martin 12th A

The complete list of JavaScript Object is listed below:

JavaScript Object Properties: A JavaScript property is a member of an object that associates a key with a value.

  • Instance Properties: An instance property is a property that has a new copy for every new instance of the class.

Instance Properties

Description 

Example 

constructor Returns a reference to the object constructor function that has created the instance of an object. 
Try

JavaScript Object Methods: JavaScript methods are actions that can be performed on objects. 

  • Static Methods: If the method is called using the Object class itself then it is called a static method of Object.

Static Methods

Description

Example

assign() Copy the values and properties from one or more source objects to a target object.
Try
create() JavaScript does not have the traditional classes seen in other languages.
Try
defineProperty() Defines a new property directly on an object and returns the object.
Try
defineProperties() Defines object a new or modifies existing properties directly on an object and it returns the object.
Try
entries() Return an array consisting of enumerable property [key, value] pairs of the object.
Try
freeze() There is a method Object.freeze() which is used to freeze an object.
Try
fromEntries() Transform a list of key-value pairs into an object.
Try
getOwnPropertyDescriptor() Returns a property descriptor for the own property of a given object.
Try
getOwnPropertyNames() Returns all properties that are present in a given object.
Try
getOwnPropertySymbols() Returns an array of all symbol properties that are present in a given object.
Try
getPrototypeOf() Check the prototype of an object that the user has created.
Try
hasOwn() Checks if a given property exists or not 
Try
Object.is() Determine whether two values are the same or not.
Try
isExtensible() Checks whether an object is extensible or not.
Try
isFrozen( ) Determine if an object is frozen or not.
Try
isSealed( ) Determine if an object is sealed or not.
Try
keys() Return an array whose elements are strings corresponding to the enumerable properties.
Try
preventExtensions() Additionally, it prevents the prototype of the item from being changed.
Try
seal() There is a method Object.seal() which is used to seal an object.
Try
setPrototypeOf() The internal [[Prototype]] property of a specified object to another object or null.
Try
toLocaleString() It returns a string representing the object.
Try
values() Return an array whose elements are the enumerable property values found on the object.
Try
  • Instance Methods: If the method is called on an instance of a date object then it is called an instance method.

Instance Methods

Description

Example

defineGetter() Called when the specified property is looked up
Try
hasOwnProperty() Check whether the object has the specified property as its own property.
Try
isPrototypeOf() Checks if an object exists in another object’s prototype chain.
Try
IsEnumerable() Returns a Boolean indicating whether the specified property is enumerable and is the object’s own property.
Try

RELATED ARTICLES

Most Popular

Recent Comments