Shorter way to declare multiple variables in JavaScript?

"Faster"? You've determined there's a performance bottleneck here?!

In any case, you can declare multiple variables:

let foo    = 'foo'
  , bar    = 'bar'
  , foobar = 'foobar'
  ;

But this is simply JS syntax–is this what you are really asking?

If you have a "large" number of related variables the problem may be more systemic, and there are multiple types of refactorings that might help.

Updated: I used to declare variables like this; I don't anymore.


This is more of a general JS syntax question.

Depending on your use case, you can just destructure an array as such:

const [ foo, bar, foobar ] = [ 'foo', 'bar', 'foobar' ]

Note that these are constants, having a lot of variables in a scope makes it poorly readable. See here for more