为什么在JavaScript中为块范围的变量声明选择了“let”的名称? [英] Why was the name 'let' chosen for block-scoped variable declarations in JavaScript?

查看:431
本文介绍了为什么在JavaScript中为块范围的变量声明选择了“let”的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我明白为什么 var 接受该名称 - 它是变量, const - 它是一个常量,但是什么是 let 的名称背后的意思,它覆盖当前块?让它成为?

I understand why var takes that name - it is variable, const - it is a constant, but what is the meaning behind the name for let, which scopes to the current block? Let it be?

推荐答案

让我们是一个数学声明,被早期的编程语言(如Scheme和Basic)所采纳。变量被认为是低级别的实体,不适合更高级别的抽象,因此许多语言设计者希望引入类似但更强大的概念,如Clojure,F#,Scala,其中 let 可能意味着可以分配但不能更改的值或变量,这反过来又使编译器捕获更多编程错误并优化代码。 JavaScript从一开始就有 var ,所以他们只需要另外一个关键字,只是从数十种其他使用的语言借来,让尽可能接近 var 作为传统关键字,尽管在JavaScript let 中创建块范围本地变量。

Let is a mathematical statement that was adopted by early programming languages like Scheme and Basic. Variables are considered low level entities not suitable for higher levels of abstraction, thus the desire of many language designers to introduce similar but more powerful concepts like in Clojure, F#, Scala, where let might mean a value, or a variable that can be assigned, but not changed, which in turn lets the compiler catch more programming errors and optimize code better. JavaScript has had var from the beginning, so they just needed another keyword, and just borrowed from dozens of other languages that use let already as a traditional keyword as close to var as possible, although in JavaScript let creates block scope local variable instead.

这篇关于为什么在JavaScript中为块范围的变量声明选择了“let”的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆