I always thought I could just check an undefined var by comparing it to undefined, but this is the error I get in the chrome console :
As far as I know you can do
if(typeof X == 'undefined')
But there are resources loader you might want to take a look at. And the answer given before me is also correct.