How can i pass an object as a perameter to a function and return an object from a function?

1 answer

Answer

1262887

2026-08-15 09:25

+ Follow

JavaScript
JavaScript

In JavaScript, you can pass an object as a parameter to a function by simply including it in the function's parameter list. For example:

<code class="language-JavaScript">function processObject(obj) {

// Modify or work with the object obj.newProperty = 'New Value'; return obj; // Return the modified object }

</code>

You can call this function like so:

<code class="language-JavaScript">const myObj = { existingProperty: 'Old Value' };

const updatedObj = processObject(myObj);

</code>

Here, updatedObj will contain the modified object with the new property added.

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.