本文介绍了变量声明是否与变量的绑定相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! MDN 文档状态:是引用的 let 绑定( let 和 const )只是关键字 let ,还是仅仅是存储空间的创建(与关键字无关)?Is the "let binding" referrred to (the hoisting of let and const) just the keyword let, or is it just the creation of storage space (which doesn't have to do with the keyword)?以前,我认为变量关键字和变量名称共同构成了一个声明,但是在问题我最近问过,回答者说它们实际上是一个初始化。Previously I thought the variable keyword and variable name together comprised a declaration, but in a question I asked recently, the answerer said they are actually an initialization.推荐答案对不起,我使用了两个撰写该MDN段落时使用不同的术语。为了该文章中的所有目的,变量和绑定应理解为同一件事。但是,让我们详细介绍一下。I'm sorry for using two different terms when writing that MDN paragraph. For all purposes in that article, "variable" and "binding" should be understood as the same thing. But let's go into details. A 变量声明创建变量(作为抽象实体)。它告诉编译器应该引入一个新变量,还可以告诉它一个名称,要保留的类型,一个初始值,一个范围等(取决于语言)。在JS中,有不同类型的声明可以执行不同的操作,例如A variable declaration creates the variable (as an abstract entity). It tells the compiler that it should introduce a new variable, and also can tell it about a name, a type to be held, an initial value, a scope etc. (depending on the language). In JS, there are different kinds of declarations that do different things, for example var 具有名称,可选的初始化程序和特定于 var 函数有一个(有时是可选的)名称,该值始终是给定的并且已知是一个函数 const 有一个名称,必需的初始化程序,应该是不变的,并且具有词法作用域 …var has a name, an optional initialiser and scoping rules specific to varfunction has a (sometimes optional) name, the value is always given and known to be a functionconst has a name, a required initialiser, should be immutable, and has lexical scoping… A 绑定是变量名称与变量实体的关联,例如 x 指的是用 class x 声明的变量。这样的绑定取决于作用域,即在每个不同的作用域中都有不同的绑定,因此标识符 x 可能引用不同作用域中的不同 things 。 给定JavaScript的范围规则,变量声明也会导致在各自的作用域中为其自身创建绑定。A binding is the association of a variable name with the variable entity, for example "x refers to the variable declared with class x". Such bindings depend on the scope, i.e. in every different scope there are different bindings and so the identifier x might refer to different things in different scopes.Given the scoping rules of JavaScript, a variable declaration also causes bindings for itself to be created in the respective scopes.因此,绑定就是使名称可供使用。这就是我所说的 let 绑定是在范围的顶部创建的。它与现有变量,已为其分配内存或正在初始化的变量无关。So the binding is what makes the name available to be used. That's what I referred to as "the let binding is created at the top of the scope". It has nothing to do with the variable existing, having memory allocated for it, or being initialised. 这篇关于变量声明是否与变量的绑定相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-22 12:44