r/javascript • • Oct 24 '16

help The only thing I hate about const ...

... is that it is 5 chars long.

For some reason, let with its 3 chars, looks more elegant.

7 Upvotes

49 comments sorted by

View all comments

4

u/saadq_ Oct 24 '16 edited Oct 24 '16

Man, this sub is volatile, haha. I got a pretty negative reaction when I mentioned the same thing a few months ago.

I agree with you, especially in cases where you have a mix of const/let variable declarations like:

const var1 = []
const var2 = {}
let var3 = 30
let var4 = 40

It would look neater if you used let everywhere (although of course you lose the added safety of const)

let var1 = []
let var2 = {}
let var3 = 30
let var4 = 40

Although I have seen a lot of people who do use let everywhere, and only use const for imports and for the old way of declaring "constants":

const fs = require('fs')
const MINIMUM_PAYMENT = 5

// Use `let` for everything else

I know Mozilla does it that way ^

4

u/Retsam19 Oct 24 '16

In fairness, "const is 5 letters long" is pretty off-topic in a thread about the performance implications of const; I'm not surprised you got flak for that reply.

1

u/saadq_ Oct 25 '16

Yeah that's true, but based on the responses it seemed like it had more to do with complaining about const rather than it being off-topic.