Skip to main content
added 20 characters in body
Source Link
Daniel Vassallo
  • 345.7k
  • 72
  • 513
  • 447

In JavaScript (pre ECMAScript 5), undefined is not a constant, but a global variable, and therefore it is possible to change its value. Therefore it would be more reliable to use the typeof operator to check for undefined:

if (typeof _var === 'undefined') { }

In addition your expression would return a ReferenceError: _var is not definedReferenceError if the variable _var is not defineddeclared. However you canwould still be able to test it with the typeof operator as shown above.

Therefore, you may wantprefer to use the following:

if (typeof _var === 'undefined' || _var === null) { }

In JavaScript (pre ECMAScript 5), undefined is not a constant, but a global variable, and therefore it is possible to change its value. Therefore it would be more reliable to use the typeof operator to check for undefined:

if (typeof _var === 'undefined') { }

In addition your expression would return a ReferenceError: _var is not defined if _var is not defined. However you can still test it with the typeof operator as shown above.

Therefore, you may want to use:

if (typeof _var === 'undefined' || _var === null) { }

In JavaScript (pre ECMAScript 5), undefined is not a constant, but a global variable, and therefore it is possible to change its value. Therefore it would be more reliable to use the typeof operator to check for undefined:

if (typeof _var === 'undefined') { }

In addition your expression would return a ReferenceError if the variable _var is not declared. However you would still be able to test it with the typeof operator as shown above.

Therefore, you may prefer to use the following:

if (typeof _var === 'undefined' || _var === null) { }
added 104 characters in body
Source Link
Daniel Vassallo
  • 345.7k
  • 72
  • 513
  • 447

In JavaScript (pre ECMAScript 5), undefined is not a constant, but a global variable, and therefore it is possible to change its value. Therefore it would be more reliable to use the typeof operator to check for undefined:

if (typeof _var === 'undefined') { }

In addition your expression would return a ReferenceError: _var is not defined if _var is not defined. However you can still test it with the typeof operator as shown above.

Therefore, you may want to use:

if (typeof _var === 'undefined' || _var === null) { }

In JavaScript, undefined is not a constant, but a global variable, and therefore it is possible to change its value. Therefore it would be more reliable to use the typeof operator to check for undefined:

if (typeof _var === 'undefined') { }

In addition your expression would return a ReferenceError: _var is not defined if _var is not defined. However you can still test it with the typeof operator as shown above.

Therefore, you may want to use:

if (typeof _var === 'undefined' || _var === null) { }

In JavaScript (pre ECMAScript 5), undefined is not a constant, but a global variable, and therefore it is possible to change its value. Therefore it would be more reliable to use the typeof operator to check for undefined:

if (typeof _var === 'undefined') { }

In addition your expression would return a ReferenceError: _var is not defined if _var is not defined. However you can still test it with the typeof operator as shown above.

Therefore, you may want to use:

if (typeof _var === 'undefined' || _var === null) { }
Post Undeleted by Daniel Vassallo
Post Deleted by Daniel Vassallo
Source Link
Daniel Vassallo
  • 345.7k
  • 72
  • 513
  • 447

In JavaScript, undefined is not a constant, but a global variable, and therefore it is possible to change its value. Therefore it would be more reliable to use the typeof operator to check for undefined:

if (typeof _var === 'undefined') { }

In addition your expression would return a ReferenceError: _var is not defined if _var is not defined. However you can still test it with the typeof operator as shown above.

Therefore, you may want to use:

if (typeof _var === 'undefined' || _var === null) { }