Monday, March 19, 2018

javascript: 檢查變量是不是undefined

如果想檢查變量是不是underfined,可以用typeof 來取得變量的類型字串。

if (typeof myObject !== "undefined") {
    alert('myObject is existed');
}


No comments: