Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript if variable is not null

Tags:

javascript

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

Using the above I run into the follow error: Uncaught TypeError: Cannot read property 'x' of null

I have tried console.log(location.x) which results in an example with null

like image 876
ngplayground Avatar asked Sep 21 '26 18:09

ngplayground


2 Answers

if (location && location.x) {

}    
like image 150
Fabio Avatar answered Sep 24 '26 07:09

Fabio


You can just do:

if (location && location.x) {

}
like image 26
tymeJV Avatar answered Sep 24 '26 08:09

tymeJV



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!