Loading topic
true or false, the engine converts it for that one check. This chapter covers where that conversion happens and how it works. Later chapters cover which values come out false.2 min readlet and const, know JavaScript's primitive types, and can read if statements and console.log output. The previous chapter covered where JavaScript converts a value to a boolean. This one covers which values become false when that 2 min readif statements and the ternary operator, and can read console.log output. It also builds on the previous chapter's list of eight falsy values.2 min readconsole.log output. So far, JavaScript has done the conversion to a boolean for you, inside if, while or a ternary. Sometimes you need the boolean itself as a value. You m2 min readconsole.log output, and are comfortable with if statements and the ternary operator.2 min readconsole.log output, and you have seen in the previous chapter how || returns one of its operands. The && operator follows the same idea in the opposite direction.2 min read|| returns the first truthy operand and && returns the first falsy operand, as covered in the previous two chapters. You should also be comfortable writing functions and reading console.log output.2 min read|| returns one of its operands, and that || skips its right side once the left side is truthy. Here you will see how those rules combine into a common pattern for setting defaults, and where that pattern quietly breaks.2 min read|| returns one of its operands, and why || replaces valid values like 0 and "" when you use it for defaults. Here you will learn the operator built to fix that problem.2 min read?? falls back only on null and undefined, and how short-circuit evaluation skips the right-hand side of && and ||. Optional chaining applies the same idea to property access and function calls.2 min read||, && and ?? choose an operand, and that the right-hand side is skipped when the left side decides the result. Logical assignment operators combine those rules with assignment in a single step.2 min read&&, || and ?? choose which operand to return, and how short-circuit evaluation skips the right-hand side. Here the question is grouping. When one expression contains several logical operators, which one runs first?2 min read&& and || return one of their operands, and how ?? and ?. work. Here those pieces are put to work as guards. A guard is an expression or statement that stops code from running when a value is missing or unusable.2 min readif converts its condition with the same rules as Boolean(). Here we compare that conversion with the loose equality operator ==. Many developers assume the two follow the same rules. They do not.2 min read|| and ?? choose a fallback, and how optional chaining stops at null or undefined. It covers the one exception to the rule that every object is truthy.2 min read