Loading topic
for...in and for...of. They differ by one word, and they answer different questions about your data. for...in asks "what are the names of this object's properties?" for...of asks "what values does this collection produce, one after another?4 min readlet and const, how to create objects and read their properties with dot and bracket notation, and how to write simple functions. It covers the syntax of for...in, what the loop variable holds on each pass, and the mistakes peo4 min readfor...in loop, create objects with literals and classes, and read properties with dot and bracket access. It explains why some properties appear in a for...in loop and others never do, even though you can read them directly.4 min readfor...in produces string keys and what makes a property enumerable. It also assumes you have a rough idea that objects link to other objects through a prototype. The prototype detail that matters here is that for...in does not stop at the object you hand it. It 4 min readfor...in walks an object's enumerable string keys, and that it also visits keys inherited through the prototype chain. You should also be comfortable with object literals, Object.keys, and Object.create.4 min readlet and const, can read and write array and object literals, and are comfortable with arrow functions. The previous chapters covered for...in, which hands you property keys. This chapter covers for...of, which hands you values, and the syntax rules and common er4 min readfor...of syntax. This chapter covers what you can put on the right-hand side of of. JavaScript ships with several built-in iterable types. Each one decides what values it produces and in what order. Once you know these rules, you can predict any for...of loo4 min readfor...of syntax from the earlier chapters and that strings are iterable. It also helps to know that str[i] and str.length exist. It does not assume you know how Unicode works. The parts you need are explained here.4 min readfor...of syntax, the built-in iterables (Array, String, Map, Set), and basic destructuring assignment with const [a, b] = pair and const { x } = obj. It shows how to put a destructuring pattern directly in the loop head, so each value the iterable produces4 min readfor...of walks the values of an iterable and how array destructuring works in a loop head. It also assumes you know what makes a property enumerable and how for...in picks up inherited keys. Here you combine those ideas to loop over ordinary objects, whi3 min readfor...in walks enumerable string keys, including inherited ones, and how for...of walks the values of an iterable. Both were covered in earlier chapters. Here we put the two loops side by side on arrays and look at the bugs that appear when for...in is4 min readlet, const and var differ in scope, and that you can write arrow functions. It also assumes you have met for...of and for...in in earlier chapters. The question here is narrow but causes real bugs: when a function created inside a loop refers to the loop v4 min readfor...of syntax and the built-in iterables (arrays, strings, Maps, Sets). It also assumes you know object literals, computed property keys such as [key]: value, and method shorthand. Here we look at what for...of does each time it runs. Once you know the m4 min readfor...of drives an iterator by calling next() (covered in the previous chapter). You should also be comfortable with generator functions (function*), try...finally, and plain objects that hold methods. The goal is to understand what each way of leaving or sk4 min readfor...of consumes an iterable: it calls [Symbol.iterator]() and then calls next() until done is true. It also assumes you have seen generator functions (function* and yield) and JavaScript classes. Here you move from consuming iterables to building the4 min readfor...of over arrays, Maps and Sets, the for...in basics, and destructuring with entries(). You should also be comfortable with splice, filter and the Map and Set methods set, add and delete.4 min readfor...of uses Symbol.iterator and next(), how generator functions work, and how Promises and async/await behave. Here you will extend the same loop to data that arrives over time, such as pages from an API, lines from a file, or chunks from a network strea4 min readlet and const, arrays and objects, arrow functions, and async/await. It also builds on earlier chapters: for...in walks enumerable string keys, including inherited ones, and for...of walks the values that an iterable produces. Here we put fou4 min read