Storing in a variable

Assigns the returned object to a variable for direct access within the same scope, offering simplicity and convenience in handling single objects.

Example: The below code uses a JavaScript variable to store an object sent by a function in JavaScript.

Javascript




function returnObject() {
    const GFG = {
        name: "w3wiki",
        est: 2009
    }
    return GFG;
}
 
const obj = returnObject();
console.log(obj.name,
    "was established in year:",
    obj.est);


Output

w3wiki was established in year: 2009

How to Store an Object sent by a Function in JavaScript ?

When a function in JavaScript returns an object, there are several ways to store this returned object for later use. These objects can be stored in variables, array elements, or properties of other objects. Essentially, any data structure capable of holding values can store the returned object.

Table of Content

  • Storing in a variable
  • Storing in an array

Similar Reads

Storing in a variable

Assigns the returned object to a variable for direct access within the same scope, offering simplicity and convenience in handling single objects....

Storing in an array

...