Skip to main content
InterviewHubPRO
Section Overview
Q23

Question 23 of 536

Part 1: Core Objects, Prototypes, Functions & Scope (1 - 53)

4%
JavaScript & V8 Internals (536 Qs)•Part 1: Core Objects, Prototypes, Functions & Scope (1 - 53)

What is the reason to choose the name let as a keyword

junior LevelMost AskedCode ExamplePrototypes

The keyword let was chosen because it originates from mathematical notation, where "let" is used to introduce new variables (for example, "let x = 5"). This term was adopted by several early programming languages such as Scheme and BASIC, establishing a tradition in computer science. JavaScript follows this convention by using let to declare variables with block scope, providing a modern alternative to var. The choice helps make the language more familiar to programmers coming from other languages and aligns with the mathematical practice of variable assignment.

Practical Code Example

javascript
// 'let' originated from mathematical notation: 'Let x = 10 in expression'
// In JavaScript, it explicitly signals block-scoped binding:
function calculateDiscount(price) {
  let finalPrice = price; // scoped to function
  if (price > 100) {
    let discount = 20;    // scoped strictly to this if-block
    finalPrice -= discount;
  }
  // console.log(discount); // ReferenceError: discount is not defined
  return finalPrice;
}
console.log(calculateDiscount(150)); // 130