0

ES6: Use Destructuring Assignment to Pass an Object as a Function’s Parameters

In some cases, you can destructure the object in a function argument itself.

Consider the code below:

const profileUpdate = (profileData) => {
const { name, age, nationality, location } = profileData;
// do something with these variables
}

This effectively destructures the object sent into the function. This can also be done in-place:

const profileUpdate = ({ name, age, nationality, location }) => {
/* do something with these fields */
}

This removes some extra lines and makes our code look neat.

This has the added benefit of not having to manipulate an entire object in a function; only the fields that are needed are copied inside the function.


Use destructuring assignment within the argument to the function halfto send only maxand mininside the function.

SOLUTION:

const stats = {
  max: 56.78,
  standard_deviation: 4.34,
  median: 34.54,
  mode: 23.87,
  min: -0.75,
  average: 35.85
};
const half = (function() {
  "use strict"; // do not change this line

  // change code below this line
  return function half({max, min}) {
    // use function argument destructuring
    return (max + min) / 2.0;
  };
  // change code above this line

})();
console.log(stats); // should be object
console.log(half(stats)); // should be 28.01

Definition – What does Web Programming mean?

Web programming refers to the writing, markup and coding involved in Web development, which includes Web content, Web client and server scripting and network security. The most common languages used for Web programming are XML, HTML, JavaScript, CSS and PHP. Web programming is different from just programming, which requires interdisciplinary knowledge on the application area, client and server scripting, and database technology.

At some point most web developers will be in the position of having to either provide hosting for their clients’ websites, or they will need to know which web hosts to recommend to their clients. Web hosting services store and activate all the files your website needs in order to function and to be active. Some of the best web hosting companies are: HostGator, GoDaddy, Bluehost, iPage, InMotion Hosting, HostFav, DreamHost, Interserver, Namecheap, 1 & 1, Fasthosts, Hostinger, GreenGeeks, Justhost, SiteGround, Host1Plus, eUKhost, Arvixe, FatCow, HostMonster and more.

Web Programming Degree

If you have a passion for connecting people through technology, our online Web Programming degree will provide you with in-demand skills to do so in a growing industry. In our program, you’ll become proficient in Java, Microsoft Azure, Google Developers Training, Web development and cloud computing—all of which help you prepare for various types of web programming roles, such as web developer, front-end developer, back-end developer or web app developer.

Through online Web Development courses, you’ll build your own professional portfolio for your future employers.

Related Post

Matlab

Leave a Reply

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

7 + 2 =