I have the following JSON response from a ajax-request.
var json = {
\"response\": {
\"freeOfChargeProduct\": {
\"description\": \"Prod
if(x && typeof x.y != 'undefined') {
...
}
// or better
function isDefined(x) {
var undefined;
return x !== undefined;
}
if(x && isDefined(x.y)) {
...
}
This will work for any data type in JavaScript, even a number that is zero. If you are checking for an object or string, just use x && x.y
within the if statement, or if you already know that x is an object, if(x.y) ...