JS | How to make one variable a link to another

Viewed 29

Instead of just assigning the value of var b to var a via a = b;,

I‘d like to make a ‚link‘ to b, so that when a is changed, actually b is changed and when a is used, actually b is used, so to say. Is that possible?

My code has immensely long arrays, and setters/getters aren’t always muuuch more readable. And even besides my current use case, it would be great to know whether something like that exists (in javaScript).

Thanks in advance.

1 Answers

What's wrong with using objects?

const a = {
  current: 5,
}

const b = a

b.current = 10

console.log(a, b)

Related