Skip to content

Files

Latest commit

 

History

History
21 lines (14 loc) · 1.72 KB

File metadata and controls

21 lines (14 loc) · 1.72 KB

Composibility easy #javascript

by Pawan Kumar @jsartisan

Take the Challenge

We have a "User" constructor function that accepts name and date of birth.

function User(name, birthday) {
  this.name = name;
  this.birthday = birthday;
}

Now, we want to add an age property as well but this should be calcuated based on the date of birth. What is the most efficient way of doing it so that the following code works:

let pawan = new User("Pawan Kumar", new Date(1993, 29, 1));

console.log( pawan.age ); // 31

Back Share your Solutions Check out Solutions