Question: I'm trying to cleanup some code (fix [jshint](http://www.jshint.com/) warnings).

What's the best replacement for 

```
if (x == undefined) {...}

```

?

I'm using [underscore.js](http://underscorejs.org/), is the following equivalent:

```
if (x === null || _.isUndefined(x)) {...}

```

Or am I missing some edge cases?
What is equal (`==`) to undefined? (assuming nobody did `var undefined = 'asdf'` or anything evil like that).

Answer: 
With `x == undefined` you actually check for two values of `x` - `undefined` itself and `null`. Take note, though, that absence of declared `x` variable will trigger an error here; to prevent this, use...

```
if (typeof x === 'undefined' || x === null) { ... }

```

But I actually think the true meaning of this warning is that you shouldn't check for both `null` and `undefined` in one branch of code, as these are different values.

Yet if you feel safe about this, you can turn off these particular checks in JSHint, with `eqnull` option. Then...

```
if (x == null) { ... }

```

... will check both for `null` and `undefined`, yet won't trigger the warning. Note, though, that `== undefined` comparisons are not 'covered' by this option.

---

As a sidenote, underscore's `isUndefined` method is an interesting piece of code:

```
_.isUndefined = function(obj) {
  return obj === void 0;
};

```

It's essentially the same as simple `obj === undefined`, yet covers one special case: when someone decided that it's a good idea to overwrite the value of `undefined` in their script. As `void` construct *always* returns "the real `undefined`", this function will work correctly even in this situation.
The correct replacement is:

```
if( typeof x === "undefined")

```