javascript check if var is undefined code example
Example 1: js check if undefined
let foo = undefined
//will return true
typeof foo === 'undefined'
Example 2: javascript check if undefined or null
// simple check do the job
if (myVar) {
// comes here either myVar is not null,
// or myVar is not undefined,
// or myVar is not '' (empty string).
}