3 ms·
'let' doesn't define a constant, it binds an immutable value. The semantic difference is enormous. A constant has infinite lifetime and must be known at compi
by bunderbunder 12y ago
'let' doesn't define a constant, it binds an immutable value.
The semantic difference is enormous. A constant has infinite lifetime and must be known at compile time. A let-binding has limited scope and can be bound a run-time.
In a language like Swift that distinguishes between mutable and immutable variables, a 'let' or 'var' is needed to indicate to the compiler what kind of of variable you're trying to create. Beyond that, it also makes for a cleaner language. Creating a special syntax for let statements that only applies inside the condition for an if-statement (and presumably also loops) just so you can avoid typing a few letters approaches PHP levels of unholy grammar pollution.