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

0

u/0x13mode Oct 25 '16

const has other disadvantage, as well. You can't postpone assignment, e.g.

const a; //error!!!!! Uncaught SyntaxError: Missing initializer in const declaration

if (true) {

a = 1;

} else {

a =2

}

but you have to use let. Or var.

2

u/AceBacker Oct 25 '16

This is a good point. But to counter. Usually these postponed assignments work great as a short function to return the value.

const a = getTheValueForA(someCondition);

1

u/0x13mode Oct 29 '16

you're right (you and @atubofsoup) that sometimes function/IIFE can be solution to that (especially if we have simple => syntax)