Live data from Hacker News

JavaScript variables: var and let and const

prestonlamb.com

1–10 of 69 posts

Re: JavaScript variables: var and let and const

#4
Having used Kotlin for a while now, I find it really unfortunate that `const` wasn't `val` for the sole reason that it's 5 characters instead of 3. `val` would have matched nice with `let`, and my multi-variable declaration statements could have had a nice 4-space indentation while still being all aligned.

I know it can be confused with `var`, but no one should ever use that now that `let` exists.

One of these days I'll write my own little language that compiles to TypeScript or something and fix that :)

Re: JavaScript variables: var and let and const

#6
post #2

https://jamie.build/const https://twitter.com/dan_abramov/status/1208369896880558080

Lol that first read is fantastic.

  const doesn't do shit and we all know it
Was a great intro, and absolutely true. Unfortunately I don't think this will catch on, although I agree with the author that it should.

Re: JavaScript variables: var and let and const

#7
post #2

https://jamie.build/const https://twitter.com/dan_abramov/status/1208369896880558080

Does JavaScript have value types where const might work the way the first author expects it to?

No. The only thing that makes const unique from let is that references declared as constants cannot be reassigned or else an error will be thrown. The exclusion only applies to the reference name itself and not to any of its properties as the article articulates.

Re: JavaScript variables: var and let and const

#8
post #4

Having used Kotlin for a while now, I find it really unfortunate that `const` wasn't `val` for the sole reason that it's 5 characters instead of 3. `val` would have matched nice with `let`, and my multi-variable declaration statements could have had a nice 4-space indentation while still being all aligned. I know it can be confused with `var`, but no one should ever use that now that `let` exists. One of these days I…

I like that Swift has var and let. Having the first letter be different means less typing with autocompletion.

I suppose when I get to use voice recognition for coding, there will also be less confusion.

Re: JavaScript variables: var and let and const

#10
post #2

https://jamie.build/const https://twitter.com/dan_abramov/status/1208369896880558080

Does JavaScript have value types where const might work the way the first author expects it to?

In JS, I think of any reference to an object as a pointer, and the is immutable even if its contents aren't; then everything in JS which can be considered a value which is immutable under const.

IMO it's not just a problem of const vs let, because it'll pop up again when you're trying to copy a JavaScript object, and it'll pop up again when someone has questions about garbage collection.

Post reply on HN