Skip to content

Passing an object of parameters into a function

Advertisements

We can pass an object to a JavaScript function but the name of the arguments should be same as the Object property names.

function areaOfRectangle({ l,b }) {
      return l * b;
   }


let rectangle = {
      l: 22,
      b: 10
   };


areaOfRectangle(rectangle); //220
See also  Fizz Buzz - Leetcode Challenge - Java Solution
, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.