if(typeof response != 'undefined')
That means: "Is there a variable called 'response'?". Since you are receiving that as a function parameter, there is/exists a variable called response
.
Existence of a variable does not mean that it can not be null
. Here, response
is defined/exists, but it is null
. And when you say:
if(response.hasOwnProperty('status'))
you try to invoke hasOwnProperty
on a null value, and hence you get that exception. You must do:
if (response !== null && response.hasOwnProperty(..)) { ... }