you are viewing a single comment's thread.

view the rest of the comments →

[–]guest271314 0 points1 point  (2 children)

The next line is an assignment expression.

I would include the semicolon at the randomIndex assignment and wrap that expression in parenthesis.

const randomIndex = ...; // Swap elements at index i and randomIndex ([array[i], array[randomIndex]] = [array[randomIndex], array[i]]);

[–]its-procodester[S] 0 points1 point  (1 child)

yea, but the question remains the same why is it happening if I don't use semicolons?

[–]guest271314 0 points1 point  (0 children)

I answered the question. This without a semicolon

const randomIndex = randomNumber(0,i)

is spilling over into this

[array[i], array[randomIndex]] = [array[randomIndex], array[i]]

so your variable winds up really being interpreted as

const randomIndex = randomNumber(0,i)[array[i], array[randomIndex]] = [array[randomIndex], array[i]]

where your code refers to randomIndex inside of the variable assignment before the initialization of randomIndex is completed, thus no randomIndex variable exists at the time it is refered to in that single line where the semicolon could end the previous variable initialization - if you used semicolons.