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

后端 未结 8 785
醉酒成梦
醉酒成梦 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:38

    Let uses a more immediate block level limited scope whereas var is function scope or global scope typically.

    It seems let was chosen most likely because it is found in so many other languages to define variables, such as BASIC, and many others.

    0 讨论(0)
  • 2020-12-07 07:39

    The most likely possibility is that it was the most idiomatic choice. Not only is it easy to speak, but rather intuitive to understand. Some could argue, even more so than var.

    But I reckon there's a little more history to this.

    From Wikipedia:

    Dana Scott's LCF language was a stage in the evolution of lambda calculus into modern functional languages. This language introduced the let expression, which has appeared in most functional languages since that time.

    State-full imperative languages such as ALGOL and Pascal essentially implement a let expression, to implement restricted scope of functions, in block structures.

    I would like to believe this was an inspiration too, for the let in Javascript.

    0 讨论(0)
提交回复
热议问题