JavaScript 判断空值 undefined 和 null 2018-09-12 Javascript, 笔记 JavaScript 判断空值 undefined 和 null 判断 undefined 12345var a = undefined;if (typeof(a) == "undefined"){ alert("undefined");} 判断 null 12345var a = null; if (!a && typeof(a)!="undefined" && a!=0) { alert(“is null”); } 同时判断 undefined 和 null 1234567891011var a = undefined;if (a == undefined){ alert("undefined or null");}var b = null; if (b == null) { alert("undefined or null");}