Loading topic
let and const, and return a function from another function. The previous chapter showed that functions are values. This chapter explains which variables a function can see.2 min readvar, let, and const, and that you read the previous chapter on lexical scope. In that chapter, the place where you write code decided what it can see. In this chapter, the keyword you use to declare a variable decides how large its scope is.2 min readvar, let, and const apart. It also builds on the earlier idea that scope is fixed by where code is written.2 min readlet, const, and var differ in scope, and have followed the previous chapter on how the scope chain resolves variables. Here we look at the structure the JavaScript engine uses to make that chain work. The ECMAScript specification cal3 min readvar and let scoping. It also assumes you have seen that closures capture variables rather than copies of their values. Here those two ideas combine into one of the most common JavaScript bugs.2 min readlet differs from var in loops. All code runs in Node.js 16 or later, or in a browser console.2 min read...args) and spread syntax.2 min readthis inside object methods. It explains why this often breaks inside callbacks and how arrow functions fix that through lexical scope.2 min read