I'm studying Javascript and I found a problem. I must define the constructor given some parameters. I insert them but I wanted to insert an if to check when the user inserts nothing. I'm working with the parasitic Inheritance model, but I don't know how to insert this case. Here is the part of my constructor:
function user(_id, userName, email, password, firstName, lastName, date_created, playlists) {
if (firstName === 'undefined') {
firstName = userName;
}
if (lastName === 'undefined') {
lastName = userName;
}
return {
_id: _id,
userName: userName,
email: email,
password: password,
firstName: firstName,
lastName: lastName,
date_created: new Date(),
playlists: []
};
}
Suppose that the user does not use firstName and LastName. It will return undefined. But I want to store a default value. How do I do that?