javascript にて変数が定義されているかどうか調べる

下記のように定義されていない変数を扱うとエラーが出る。

// ReferenceError: test is not defined
console.log(test)

これを回避するには typeof で判定する。

// 文字列が返る
if (typeof test == 'undefined') {
	console.log('test is undefined')
	return
}
console.log(test)