As everyone has stated it is largely preference and readability, but I'll throw a comment on the thread since I didn't see others share thoughts in this vein
I think the answer to this question is largely dependent on what variables you're setting and how they're related. I try to be consistent based on if the variables I'm creating are related or not; my preference generally looks something like this:
For unrelated variables
I single-line them so they can be easily moved later; I personally would never declare unrelated items any other way:
const unrelatedVar1 = 1;
const unrelatedVar2 = 2;
const unrelatedVar3 = 3;
For related things (utility)
If I'm creating new variables I declare as a block -- this serves as a hint that the attributes belong together
const
x = 1,
y = 2,
z = 3
;
// or
const x=1, y=2, z=3;
// or if I'm going to pass these params to other functions/methods
const someCoordinate = {
x = 1,
y = 2,
z = 3
};
this, to me, feels more consistent with de-structuring:
const {x,y,z} = someCoordinate;
where it'd feel clunky to do something like (I wouldn't do this)
const x = someCoordiante.x;
const y = someCoordiante.y;
const z = someCoordiante.z;
For related things (construction)
If multiple variables are created with the same constructor I'll often group them together also; I personally find this more readable
Instead of something like (I don't normally do this)
const stooge1 = Person("moe");
const stooge2 = Person("curly");
const stooge3 = Person("larry");
I'll usually do this:
const [stooge1, stooge2, stooge3] = ["moe", "curly", "larry"].map(Person);
I say usually because if the input params are sufficiently long that this becomes unreadable I'll split them out.
I agree with other folk's comments about use-strict
let one=1,tow=2,three=3;