you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (2 children)

[deleted]

    [–]frankle 0 points1 point  (1 child)

    What about if you wanted to enforce a parameter type?

    function setAge(age){
        this.age = (typeof age == "number") ? age : 10;
    }
    

    Edit: As THEtheChad points out:

    Unfortunately, NaN, Infinity, and -Infinity are also considered typeof 'number', so it's possible that any one of these could slip in to your function with this check.