The JavaScript You Need for Node
Node code leans on a handful of JavaScript features: arrow functions, arrays of objects, destructuring, map and filter, JSON, try and catch, promises and async/await. These lessons from JavaScript in Depth hand them over, so you can read and write every example in this course. Already comfortable with them? Take the chapter check, and skip what you pass.
Updated
Functions and Objects for Node
- Function Expressions and Arrow Functions (Apprentice): A function can be stored in a variable like any other value, arrow functions (=>) write small functions in a line, and default values fill in the arguments a caller leaves out.
- Arrays of Objects (Apprentice): An array of objects is a list of records, like a stack of filled-in forms, and it's how programs keep search results, carts and listings that you read, loop over and update.
- Destructuring (Apprentice): Destructuring unpacks the values you need from an object or an array into variables in one line, with defaults for anything missing and new names when you want them.
Reshaping Data for Node
- map and filter (Apprentice): map turns every item of an array into something new, filter keeps only the items that pass a test, and chained together they turn raw data into exactly the list a screen needs.
- reduce (Journeyman): reduce walks through an array carrying a running total, so a whole list of scores, prices or plays boils down to one answer, such as a total, a count or a best score.
- JSON: Data You Can Save and Send (Apprentice): JSON is the text format the web uses to save and send data, and JSON.stringify and JSON.parse turn your objects and arrays into JSON text and back, as long as the text follows JSON's strict rules.
Waiting and Errors for Node
- Handling Errors with try, catch and finally (Apprentice): try runs code that might fail, catch takes over when it does and gets an error object with a name and a message, and finally runs either way, so one bad value doesn't stop your whole program.
- Promises: then, catch and finally (Journeyman): A promise is a value that arrives later, like the buzzer a pizza shop hands you, and then, catch and finally say what to do when it works, when it fails, and either way.
- async and await (Journeyman): async and await let you write code that waits for promises as if it were a recipe, one step under another, with try and catch for the steps that fail.
Exercise: Food Truck Orders
- Exercise: Food Truck Orders (Apprentice): Finish the Rolling Noodle food truck's order functions, a day's total with reduce, one dish's orders with filter, receipt lines with map and destructuring, JSON both ways and an async loader with a clear error, and let node --test check each one.