A shorter way to declare multiple variables in JavaScript?

Is there a faster / more efficient way to declare multiple variables in a native reaction? Instead

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

Obviously, the problem is not for three variables, but for large sets of variables, is there a better way?

+4
source share
2 answers

"Faster"? Have you identified a performance bottleneck here ?!

In any case, you can declare several variables:

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

But it is JS 101 and trivially searchable. What are you really asking?

In addition, if you have a "large" number of variables, I suspect that the problem is more systemic and you are missing several types of refactoring.

+9

JS.

:

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

, , , . .

+4

Source: https://habr.com/ru/post/1665034/


All Articles