Check out this starting code snippet.
function person(name, age, child){
this.name = name;
this.age = age;
if(this.child == undefined){
this.child = 'default';
}else{
this.child = child;
}
}
var sarah = new person('sarah',34,true);
document.write(sarah.child+' ');
I'm attempting to include an optional property in a constructor function. However, regardless of what I provide as the value for the child parameter, it always displays 'default' when outputted. I am relatively new to JS, coming from a background in PHP. I can't figure out why this isn't working. I've researched other similar issues and tried various solutions, but nothing seems to fix the problem.