Wednesday, November 24, 2021

What is Arrow function in javascript?

Arrow functions introduced in ES6. It  provides a concise way to write javascript function.

//ES5

const years=[1990,2000,2010,2020];

var ages= years.map(function(el){

   return 2021-el;

});

console.log(ages);

//ES6

const years = [1990,2000,2010,2020];

let ages = years.map(el=>2021-el);//This is called arrow function.

console.log(ages);

//Arrow function with multiple parameter

const years = [1990,2000,2010,2020];

let ages = years.map((el,index)=>`age element ${index+1}:${2021-el}`);

console.log(ages);



No comments:

Post a Comment

Element of a good table (Ref: Database design mere mortals by Michael J. Hernandez)

  Elements of the Ideal Table: It represents a single subject, which can be an object or event that reduces the risk of potential data integ...