var myVar = null;
console.log(myVar.test)
The above code returns this error: Uncaught TypeError: Cannot read property 'test' of null
.
How can I just get it to return null without any errors?
I could use a try/catch
or an if
statement to first check myVar
, but is there a simpler way?