Definition

An object in JavaScript is a standalone entity, with properties and type. It's a collection of key-value pairs where each key (or property) is a string (or Symbol) and the value can be anything (primitive data types, other objects, functions, etc.). Objects are used to store data and more complex entities.

Code Example

Here is a simple example of an object in JavaScript:

// Creating an object
const person = {
	// state
  firstName: "John",
  lastName: "Doe",
  age: 30,
  isMarried: false,
  // Method (function within an object) or behaviour
  fullName: function() {
    return this.firstName + " " + this.lastName;
  }
  nameWithAge(){
		  return this.firstName + " is of age " + this.age 
  }
};

// Accessing object properties
console.log(person.firstName); // Output: John
console.log(person["lastName"]); // Output: Doe

// Calling a method within an object
console.log(person.fullName()); // Output: John Doe

// Adding a new property
person.occupation = "Engineer";

// Modifying a property
person.age = 31;

console.log(person);

Major Uses in React and JavaScript

  1. State Management in React
  2. Props in React
  3. Configuration Object
  4. Data Structure
  5. Functional Programming

Objects are a fundamental part of JavaScript and are extensively used in various ways to structure and manage data in applications. Understanding how to create, manipulate, and utilize objects is crucial for effective JavaScript and React development.

Major Uses

Clone of object

Array

Getter and Setter