Re:JavaScript variables: var and let and const
by bryanrasmussen on Friday March 06, 2020 @03:22PM
(#22506958)
I'm supposing the reason const is const is because it was in the list of reserved words quite early https://www-archive.mozilla.org/js/language/E262-3.pdf section 7.5.3 Future Reserved Words - whereas of course val is probably a really common variable name in multitudinous little scripts all over the world and it would basically break the internet if it was used.
I would suggest con, but hey that would probably also break a lot of stuff and const wouldn't break anything because being a reserved word you should never have named or been able to name your variable const (probably some JavaScript engine somewhere would have let you though, like early IE/Netscape might have made that mistake)
Re:JavaScript variables: var and let and const
by hombre_fatal on Friday March 06, 2020 @03:14PM
(#22506871)
A solution I prefer is Rust's where the immutable binding is default "let x" and you opt-in with a modifier to make it mutable "let mut x".
It just makes sense for the immutable case to be default by design instead of just by developer habit.
"var" vs "val" always were too similar for me.
Re:JavaScript variables: var and let and const
by bobbylarrybobby on Friday March 06, 2020 @06:01PM
(#22508176)
Swift’s var and let are also good. There is no “default” but “let” is obviously preferred
Re:JavaScript variables: var and let and const
by melling on Friday March 06, 2020 @02:29PM
(#22506457)
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
by eyelidlessness on Friday March 06, 2020 @02:52PM
(#22506678)
Generally speaking most languages treat `let` as constant/immutable, and the real shame is that JS did not. It's understandable why (they needed a block-scoped `var`), but unfortunate nonetheless.
Re:JavaScript variables: var and let and const
by chrisseaton on Friday March 06, 2020 @03:46PM
(#22507147)
> for the sole reason that it's 5 characters instead of 3
Are you being charged by the character or something?
Re:JavaScript variables: var and let and const
by setr on Friday March 06, 2020 @03:53PM
(#22507203)
Formatting..!
Re:JavaScript variables: var and let and const
by dkarl on Friday March 06, 2020 @03:35PM
(#22507078)
My experience with Scala is that `var` and `val` fortunately look very different in source code. `var` jumps right out at me, perhaps because the shape of the word is so different.
Re:JavaScript variables: var and let and const
by masswerk on Friday March 06, 2020 @11:10PM
(#22509679)
Mind that JavaScript simply reused the set of reserved keywords from Java. This similarity in keywords and syntax is, what made the "Java" part in "JavaScript", while there is actually no deeper relation between the two languages. `const` was available. (However, `let` wasn't in that set, nor in the reserved ECMA extension.)
Re:JavaScript variables: var and let and const
by the_other_b on Friday March 06, 2020 @04:14PM
(#22507368)
Genuine question (and hoping for your opinion here), why would I use Kotlin over Java? Outside the obvious like developing on Android.
I haven't had much exposure to it, but it seems like it has a wider breadth of features and has a quicker development speed?
Re:JavaScript variables: var and let and const
by rkrishnaan on Friday March 06, 2020 @04:24PM
(#22507449)
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 :)