How to handle undefined value in JavaScript

How to handle undefined value in JavaScript?

if (oldins == ins)

oldins not determined.

How to check it?

+5
source share
3 answers
if ((typeof(oldins) !== "undefined") && (oldins === ins))
+7
source

Undefined variables will be evaluated to undefined. 'undefined' is a type of value such as null and NaN, so it will look like this:

if ( typeof(oldins) == 'undefined' )

Edit: fixed for each comment. Leaving the answer as comments are useful, but there were more correct answers.

+3
source
if (oldins !== undefined && oldins === ins) {

}
+1
source

All Articles