Johnston Johnston - 3 months ago 8
Javascript Question

Is this variable global in ES6?

Given the following abridged code (in ES6):

for (let i = 0, labelsLength = this.predefinedLabels.length; i < labelsLength; i++) {
...


Is
labelsLength
being made into a global (
window
) variable?

Assuming this is the entire context you have.

Answer

It is not a global variable.

Mozilla Developer Network here states:

The let statement declares a block scope local variable, optionally initializing it to a value.

Syntax

   let var1 [= value1] [, var2 [= value2]] [, ..., varN[= valueN]];

As you can see multiple declarations seperated by commas is fully supported.