- 判斷變數為 null 或 undefined 或 “”
if(!str) { var str; console.log("str is null or undefined or '' "); }
- 判斷變數是否存在
if(typeof str === "undefined") console.log("str is not exist");
PS. === 可以辨別型態, == 則會轉型單純比值
參考資料:
camel's blog
camel's blog
if(!str) { var str; console.log("str is null or undefined or '' "); }
if(typeof str === "undefined") console.log("str is not exist");
PS. === 可以辨別型態, == 則會轉型單純比值
參考資料:
Leave a Reply