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 ^

1

u/factorysettings Oct 24 '16 edited Oct 25 '16
const var1 = [],
      var2 = {};
let var3 = 30,
    var4 = 40;

?

1

u/saadq_ Oct 25 '16

I guess the argument I was making is that it looks nicer if you use exclusively one out of const/let because everything can line up:

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