EDIT: Existing answers are 2 and 5 years old (from 2017 and 2014).
How can I shorten the following statement
ratingsExisting(): boolean {
return (
this.fromAPIData.book &&
this.fromAPIData.book.misc &&
this.fromAPIData.book.misc.ratings &&
this.fromAPIData.book.misc.ratings.length > 0
);
}
so that I don't receive errors if any of the properties is null?
this.fromAPIData?.book?.miscwill hopefully be part of both JS and TS soon ... till then you have to fall back to other syntactic sugars shown in the dupe.