下記のように定義されていない変数を扱うとエラーが出る。
// ReferenceError: test is not defined
console.log(test)
これを回避するには typeof で判定する。
// 文字列が返る
if (typeof test == 'undefined') {
console.log('test is undefined')
return
}
console.log(test)
日々の積み重ねを書き溜めています
下記のように定義されていない変数を扱うとエラーが出る。
// ReferenceError: test is not defined
console.log(test)
これを回避するには typeof で判定する。
// 文字列が返る
if (typeof test == 'undefined') {
console.log('test is undefined')
return
}
console.log(test)