DEV Community

Discussion on: How should we indent `const` declarations?

Collapse
 
fpuffer profile image
Frank Puffer

I definitely prefer

const foo = 10;
const bar = 20;
const baz = 30;

not only for const but also for var and let.

It makes refactoring easier because each declaration is completely independent from the other ones. Just remove a line to remove a variable. You don't even need to change a comma to a semicolon.

Another advantage: Most search tools only show the line where the search string occurs. If you search for all occurences of bar in your editor, you might prefer to see

const bar = 20;

instead of

    bar = 20,

as a result because it provides more information.

I don't believe that typing a few more keywords will slow down your coding significantly.

Collapse
 
kenbellows profile image
Ken Bellows

Clearer search results is an interesting point I hadn't heard before. 🤔 Nice one, I'll have to think on that