如果变量不为null,则为Javascript

ngp*_*und 2 javascript

if (typeof (location.x != null) {

使用上面我遇到了以下错误: Uncaught TypeError: Cannot read property 'x' of null

我试过console.log(location.x)用一个例子得到的结果null

Fab*_*bio 7

if (location && location.x) {

}    
Run Code Online (Sandbox Code Playgroud)