Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #17972

Re: typeof and jslint

From Stefan Weiss <krewecherl@gmail.com>
Newsgroups comp.lang.javascript
Subject Re: typeof and jslint
Date 2013-01-06 01:21 +0100
Organization albasani.net
Message-ID <kcag1j$ld0$1@news.albasani.net> (permalink)
References <Ba2dnXXmp_MKKXXNnZ2dnUVZ_sydnZ2d@westnet.com.au>

Show all headers | View raw


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.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

typeof and jslint Andrew Poulos <ap_prog@hotmail.com> - 2013-01-06 10:17 +1100
  Re: typeof and jslint Luc Yen <luc@goal.tw> - 2013-01-05 15:40 -0800
    Re: typeof and jslint Andrew Poulos <ap_prog@hotmail.com> - 2013-01-06 11:04 +1100
      Re: typeof and jslint Luc Yen <luc@goal.tw> - 2013-01-05 16:33 -0800
  Re: typeof and jslint David Mark <dmark.cinsoft@gmail.com> - 2013-01-05 16:16 -0800
    Re: typeof and jslint Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2013-01-11 00:53 +0100
  Re: typeof and jslint Stefan Weiss <krewecherl@gmail.com> - 2013-01-06 01:21 +0100
  Re: typeof and jslint Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-01-06 01:21 +0100

csiph-web