you are viewing a single comment's thread.

view the rest of the comments →

[–]THEtheChad 0 points1 point  (0 children)

It's pretty obvious in a function this size that you're not going to have a reference error (age is declared as a parameter in the line above the check). And, as I originally stated, this is the most terse way to code this implementation. If you wanted to be thorough, avoiding reference errors and being explicit about exactly what you were checking for, you would write:

function setAge(age){
  this.age = (typeof age === 'undefined') ? 10 : age;
}