I get the error in the title even though I have tried all the solutions. About the value of null;
If my code is ;
Output: TypeError: Cannot read property of null
case '!facebook':
face.Profile(facebook, function(result) {
let like = result.profiles.like;
let comments = result.profiles.comments;
if(like === null || comments === null){
//code.
}
else {
//code.
}
});
break;
You have to verify that each child of your object exists before you reference the next level. In your case, that means testing the existence of result
and then result.profiles
before trying to use any of the object values in profiles
. See the code below.
Without seeing the rest of your case
statement or how you're setting the value of face
, it's hard to tell if you're going to run into other issues.
case '!facebook': face.Profile(facebook, function(result) { // Set default values let like = null; let comments = null; // Set values only if there's a result containing profiles if (result && result.profiles) { like = result.profiles.like; comments = result.profiles.comments; } if (like === null || comments === null){ //code } else { //code } }); break;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.