Loading topic
null and undefined. Together they are called nullish values. The optional chaining operator (?.) and the nullish coalescing operator (??) react to these two values and no others. Before using either operator, you need to know exactly wh5 min read|| and && operators. The previous chapter showed that only null and undefined count as nullish. This chapter explains why that matters: the most common way of wr5 min read|| replaces values like 0 and "" that you meant to keep. Both topics were covered earlier. Here we look closely at the nullish coalescing operator ??: what it does, the order it evaluates things in,5 min read&& returns one of its operands. You should already know the two nullish values, null and undefined, from the earlier chapter.6 min read?. operator from the previous chapter protects a dot access. Here we cover the bracket form, ?.[]. You use it when the property name is computed at runtime, comes from a variable, 5 min readonClose callback that callers can leave out. A plugin may implement some lifecycle hooks and skip others. A newer runtime may provide an API that an older one lacks. The optional call form, ?.(), lets you call such a function only 5 min read?. stops a property chain from throwing when it reaches null or undefined. ?? swaps in a fallback only when a value is null or undefined. This chapter puts them together, which is how most real code uses them. A typical case is readi5 min read?., ?.[] and ?.() work on their own, and that you are familiar with short-circuit evaluation in || and &&. Here we look at what happens after an optional chain finds a nullish value: which parts of the expression still run, which parts are skippe5 min read?? works and how it differs from ||. You should also be comfortable with object property access, getters and setters, and strict mode. The nullish coalescing assignment operator, ??=, combines ?? with assignment. It writes a value into a variable or 5 min read?? picks a right-hand value only when the left side is null or undefined, and how || and && short-circuit. It also assumes you know that operator precedence decides how JavaScript groups an expression that has no parentheses. Here you will learn three thin6 min read?. short-circuits property access, bracket access and calls, and how ?? supplies defaults. Here the focus is on the places where the language rejects ?., plus a few runtime errors that ?. does not prevent. Some of these mistakes stop the whole file f5 min read?., ?.[], ?.(), ?? and ??= behave, as covered in the earlier chapters. You should also be comfortable with throwing errors with throw and catching them with try...catch.6 min read?., ?? and ??= behave, which earlier chapters covered. It also assumes you have used a build tool such as Babel, TypeScript or esbuild and know what a package.json is. The question here is practical: will your code run where you deploy it? If it won'6 min read