Why was the name 'let' chosen for block-scoped variable declarations in JavaScript?

后端 未结 8 876
醉酒成梦
醉酒成梦 2020-12-07 06:47

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, whic

8条回答
  •  感情败类
    2020-12-07 07:19

    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.

提交回复
热议问题