I would like to distinguish between an undeclared variable and a declared but undefined variable in JavaScript.

Definition of UNDECLARED: There was no preceding var or global statement, and no statement that explicitly or implicitly assigns a value to the variable.

Definition of DECLARED BUT UNDEFINED: There was a preceding var statement, but no value was assigned to the variable in the var statement or subsequently.

The best I've found so far is:

This test distinguishes between defined and undefined variables, but does not distinguish between "undefined" and "defined but undeclared." Can you help?