How does multiple assignments on the same line work in JavaScript?

76 views Asked by At

I couldn't find a similar thread as to this specific case, so I decided to make one.

Basically, let's consider this snippet.

let a = [7];
const b = a;

a[0] = a = 15;

console.log(a, b) // 15 [15]

According to MDN, the assignment operator goes from right to left, so I figured 15 is assigned to a, which means a now will point to a primitive, so going to the left, a[0] shouldn't be able to modify the array element, since it's not pointing at the reference anymore. Unless I am missing something here. Maybe someone would like to explain step by step how this goes? Thank you very much.

0

There are 0 answers