On 2013-01-06 00:17, Andrew Poulos wrote:
> If I test the following with jslint
> if (typeof num === 'undefined') { return false; }
>
> I get the error
> Unexpected 'typeof'. Use '===' to compare directly with undefined.
That's just plain wrong. "num === undefined" may do the same thing, but
only if num has been declared or can be otherwise resolved from the
current scope. If you can't be sure that num exists, typeof is mandatory.
This is bad advice, and yet another reason not to use JsLint. You could
try to report this on the jslint_com mailing list, and hope that DC
agrees with you. Or you could use another linting tool like JsHint.
- stefan
PS: In addition to the above, the 'undefined' identifer is not
guaranteed to evaluate to the undefined type, but that's more of a
theoretical concern. Your original code would be safe from that.