Hi there! Out of curiosity. Why not use const
and var
instead of let
and var
in Swift? I'm intrigued because it seems easier to understand var
as variable and const
as constant. I'm a JavaScript developer, and I never understood choosing let
as the new var
, but in Swift, choosing let
as the new const
... well, it's a little bit confusing. Is there a genuine reason for this decision, or was it to avoid colliding with JavaScript? Thanks a lot in advance for your answers 🙂
There is a very subtle difference between a let in Swift and a const in other languages.
const is initialised at compile time, let may be initialised at runtime and then immutable (with a closure for instance).
So, let is wider use than const.
See very interesting discussion here: https://stackoverflow.com/questions/26063763/why-is-a-constant-declared-with-the-keyword-let-in-swift