Jslint does not like !==, seems to prefer ===, relation to typeof

backbone.js, javascript, jslint

Solution

The Underscore library (created by the same guy that made Backbone and CoffeeScript, so you know it's well-thought-out) uses the following for its `isUndefined` function:

obj === void 0

If you want a fully safe (even in the oddball case of someone redefining `undefined`) approach, that will still make cranky old Crockford (the guy who writes JSLint) happy, I'd use that check. It's sort of awkward looking though, so at the very least I'd put an explanatory comment with it.

Better yet, you could just roll it up in to your own `isUndefined` function, like Underscore. Or better yet, you could just use Underscore's function in the first place; if you're using Backbone, you already have Underscore, as Backbone requires it.

Problem

``` Unexpected 'typeof'. Use '===' to compare directly with undefined. if (typeof exports !== 'undefined') { ``` This is code from backbone.js. It does not seem to like the syntax. How can I change this code to make jslint.com happy?

Original source

Related problems