DEV Community

Discussion on: Declaring JS Variables in 2019

Collapse
 
flame10a profile image
Flame10A

I very much agree with 'const first'; it's in the same realm as Java class variables being private by default - no matter how safe your code may be, there's no harm in it being that bit safer!

let is of course good for any local variable that may change within its scope, but otherwise it's safer (e.g. in case of autocomplete shenanigans, or plain misunderstanding), and more visually meaningful, to declare a variable as unchangable.

On the odd case of function declarations... I'm very much against using the function foo() { ... } syntax out of place; much like var, the funcionality of it can be rather backwards, and in turn can be confusing to readers of any level.