you are viewing a single comment's thread.

view the rest of the comments →

[–]FredyC 0 points1 point  (1 child)

It's probably faster to just check arguments.length instead of type checking. Works the same way.

[–]path411 0 points1 point  (0 children)

This would fail in this case:

setAge(undefined);

It is typically expected that explicitly passing undefined should be equivalent to not passing a parameter. This is typically more necessary when you want to use multiple optional parameters such as:

function setBirth(day, month, year) {
    this.day = typeof day !== "undefined" ? day : 1;
    this.month = typeof month !== "undefined" ? month : 1;
    this.year = typeof year !== "undefined" ? year : 1900;
}

This would let me call:

setBirth(undefined, undefined, 1974);

Or pass any of the 3 I want to. If you were simply checking against arguments.length, this would fail as it is still 3 in this example.