Javascript Objects

share link

by vsasikalabe dot icon Updated: Feb 24, 2023

technology logo
technology logo

Guide Kit Guide Kit  

Objects are the combination of variables, functions, and data structures in programming. The objects can store values, manipulate values, and combine them into more complex objects, like arrays. You can create an object using three ways: Using an object. By creating an Object directly. By using the constructor function. An object is a set of key-value pairs. Each key-value pair is called a property. The string is the key to a property. The property value can be any of a number, a string, an array, or a function. 

Accessing properties 

We can use any one of these two notations to access a property of an object: 

  • the dot notation  
  • array-like notation. 

We can use the assignment operator (=) to change the value of a property. We use the delete operator to delete a property of an object. We can use the in operator to review when a property exists in an object. When the propertyName exists in the objectName, the in operator returns true. 

In JavaScript, "everything" is an object. 

  • If defined with the new keyword, Booleans can be objects. 
  • When the new keyword is defined with Numbers, it can be objects 
  • When the new keyword is defined with Strings, it can be objects  
  • Dates are always objects 
  • Maths are always objects 
  • Regular expressions are always objects 
  • Arrays are always objects 
  • Functions are always objects 
  • Objects are always objects 

All JavaScript values, except primitives, are objects. 

Types of Objects in JavaScript 

  • User-defined Objects - It is created to develop a software object model such as Bank accounts, students, houses, cars, companies, etc. 
  • Built-in Objects / Predefined Objects - A built-in object is an object of the primitive and non-primitive data types to handle some specific tasks. 

Here is an example of how to create Javascript Objects: