Saturday, November 27, 2021

Destructuring practical example.

When we need to return multiple values from  a function we can return a object of having the values .But using destructure we can do this . lets see the example,

function calculateRetirement(year){
    const age = new Date().getFullYear()-year;
    return[age, 65-age];
}

const[age,retirement]=calculateRetirement(1989);
console.log(`age${age} retirement${retirement}`);

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...