We are frequently using the following code pattern in our JavaScript code
if (typeof(some_variable) != \'undefined\' && some_variable != null) {
Open the Developer tools in your browser and just try the code shown in the below image.