Mots clés : javascriptvariablesinitializationundefinedjavascript
92
if (typeof variable !== 'undefined') { // the variable is defined }
81
if (typeof variable === 'undefined') { // variable is undefined }
if (typeof variable === 'undefined' || variable === null) { // variable is undefined or null }
80
if (elem) { // or !elem
if(elem) { if(typeof elem === 'string' && elem.trim()) { ///
67
if (typeof v === "undefined") { // no variable "v" is defined in the current scope // *or* some variable v exists and has been assigned the value undefined } else { // some variable (global or local) "v" is defined in the current scope // *and* it contains a value other than undefined }
if ("v" in window) { // global variable v is defined } else { // global variable v is not defined }
56
elem != null
if (elem === undefined) ...
var undefined; // really undefined if (elem === undefined) ...
(function (undefined) { if (elem === undefined) ... })();