Loading topic
if statement must choose a branch. A while loop must decide whether to run again. JavaScript does not require that answer to be true or false. You can hand it a string, a number, an object, or undefined, and th5 min readlet and const, know JavaScript's primitive types and objects, write if statements and functions, and read console.log output. The previous chapter listed the places where JavaScript expects a boolean, such as if, while, the ternary oper5 min readlet and const, know JavaScript's primitive types and objects, and can read if statements, ternaries and console.log output. You should also know the short list of falsy values from the previous chapter: false, 0, -0, 0n, "", `null5 min readlet and const, write and call functions, and read console.log output. It also assumes you have read the earlier chapters on boolean contexts and the falsy list. Those chapters showed JavaScript converting values to booleans implicitly5 min readlet and const, know the primitive types and objects, write if statements and functions, and read console.log output. It also builds on the earlier chapters: you should know the eight falsy values and that everything else is truthy.5 min readfalse, 0, -0, 0n, "", null, undefined, NaN), that every other value is truthy, and how || returns one of its operands. You should also be comfortable reading console.log output and writing small functions.4 min readlet and const, write and call functions, read console.log output, and predict which operand && and || return (covered in the two previous chapters). Here the question changes. Earlier chapters asked which value comes back. This chapter as5 min read|| returns one of its operands, and that || short-circuits. It also assumes you can read function parameters and object properties. Here we put those rules to work on one everyday task: supplying a fallback when a value is missin5 min read|| returns its first truthy operand and how short-circuit evaluation skips the right-hand side. It also assumes you have seen the default-value trap from the previous chapter, where || throws away valid values such as 0 and "". The nullish coalescing4 min read?? supplies a default only for null and undefined, and how && short-circuits. It also assumes you can read object property access in both dot form (obj.key) and bracket form (obj["key"]), and that you know what a TypeError is.5 min read||, && and ?? pick an operand, and that the right side of each is skipped once the left side decides the result. It also assumes you can read object property access, getters and setters, and console.log output. Logical assignment adds no new truthine4 min read&&, || and ?? choose and return an operand, and how short-circuit evaluation skips the right-hand side. It also assumes you can read console.log output and write small functions. Here you will learn how JavaScript groups an expression that has severa6 min read&& and || return one of their operands, how short-circuit evaluation works, and how ?? and ?. behave. Here we use those rules in real code. A guard is a check that stops code from running, or picks a safe value, when data is missing5 min readif statement, a ternary, or a logical operator. This chapter covers a different rule that looks similar and gets confused with it: loose equality with ==. When you write value == true or `value == f6 min read||, && and ?? choose an operand, and how optional chaining stops at null or undefined. Earlier chapters said that every object is truthy. Browsers have exactly one exception to that rule, document.all. You will almost neve5 min read