Loading topic
if, while, and for in JavaScript tests a condition. That condition does not need to be a boolean. You can write if (user) or while (queue.length), and JavaScript will convert whatever value you give it into true or false before deciding what to do. This chapter explains exactly h5 min readif statement and every loop condition you write later in this tutorial depends on a comparison. JavaScript has two equality operators that behave differently. Its relational operators (<, >, <=, >=) also have conversion rules that can surprise you. This chapter explains how each oper5 min readlet and const, and how to write and call functions. It also builds on the two chapters before it: how values become truthy or falsy, and how ===, ==, and the relational operators compare values. Here5 min readif statement. It also assumes you are comfortable with functions, objects, and const/let. You will learn what the logical operators return, when they skip evaluating their right side, an5 min read=== compares values, and how to write if/else chains. You should also be comfortable with const, functions, and template literals.4 min readswitch statement compares one value against a list of candidates and runs the code for the first one that matches. It does the same job as an if/else if chain whose every condition is x === something, but it puts the shared value in one place. This chapter covers how switch matches, how 5 min readif statements test a condition and how truthy and falsy values behave. You should also be comfortable declaring variables with let and const and working with arrays. Both loops covered here use the same truthiness rules as if. The only difference is that the5 min readwhile loops, compare numbers with <, <=, and ===, and index into arrays with arr[i]. The classic for loop packs the three parts of a counting loop into one line: where the counter starts, when the loop stops, and how the counter changes. Becaus5 min readfor loop and a while loop, and that you know how if statements and block scoping with let work. Every loop you have written so far stops in one place only: when its condition turns false. Real loops often need more exits. A search should stop once6 min readfor loop and break/continue from earlier chapters. It also assumes you can read arrays, plain objects, arrow functions, and array destructuring such as const [a, b] = pair. The goal is to show you how for...of works internally, which values5 min readobj[key]), and write a classic for loop. It also assumes you have seen for...of, which goes through the values of an iterable. for...in answers a different question: it goes through5 min readfor loop runs (initializer, condition, update, body). It also assumes you can write arrow functions and know that a function can use variables from the scope around it. That last idea has a name. A closure is a function together with the va6 min readfor...of loops, array methods such as map and forEach, and the basics of promises and async/await. In particular, you should know that an async function always returns a promise, and that await pauses only the function it appears in.5 min readif/switch chains 5 min read