Javascript

Home Load Console Selectors CSS Form Strings If Else Array Reg Exp Date & Time setTimeout JSON Loops Objects Animation Fat Arrow Class Import IIFE undefined Tabulator.js ES6 Event Listeners AJAX Hide Elements Create Elements Checkbox ejs
O O

Weather Controls

Time Of Day
Rain
Wind Speed
Wind Direction
Clouds

Javascript : undefined

2022-07-18

if undefined or null

var firstName;
var lastName = null;

if(firstName == null){
    alert('Variable "firstName" is undefined.');
}    

if(lastName == null){
   alert('Variable "lastName" is null.');
}

if null

var rob = document.getElementById('rob');

if(typeof rob === 'undefined') {
    alert('This will NOT show. typeof a non existing DOM element is null');
} 

if(rob === null){
    alert('This will show.');
}