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

-2

u/kevinkace Oct 24 '16

Agreed, for primarily aligning single const declarations, eg:

let thing1 = "thing1",
    thing2 = "thing2"; // nicely aligned

const thing3 = "thing3",
    thing4 = "thing4"; // like this with standard 4 spaces?

const thing5 = "thing5",
      thing6 = "thing6"; // or like this to align?

15

u/rauschma Oct 24 '16 edited Oct 24 '16

I prefer:

const thing7 = "thing7";
const thing8 = "thing8";

Easier to rearrange (especially if git is involved) and automatically aligned.

1

u/saadq_ Oct 24 '16

But what if you have a mix of const and let?

const thing7 = "thing7";
let thing8 = "thing8";

I imagine you wouldn't do this:

const thing7 = "thing7";
let   thing8 = "thing8";

1

u/rauschma Oct 24 '16

Yes, that does make things more complicated. I’d probably put the lets last, without any additional spaces before the variable names (as in your first code fragment). Looks a bit ugly, but does clearly separate groups of consts from groups of lets.

8

u/konbit Oct 24 '16

If you work in a team using git this is a horrible idea anyway. I can't count the amount of times code has broken after a merge because of this stupid pattern.

-8

u/kevinkace Oct 24 '16

Then you suck at merging.

4

u/adavidmiller Oct 24 '16

That's kind of the point. You shouldn't depend on people not sucking if you don't have to.

2

u/Cuel Oct 24 '16

Easy solution, don't align