Skip to content
DevMeme
1378 of 7435
JavaScript References Become Quantum Entanglement
Languages Post #1551, on May 9, 2020 in TG

JavaScript References Become Quantum Entanglement

Why is this Languages meme funny?

Level 1: Two Stickers, One Box

Imagine one toy box with two name stickers on it: a and b. If someone puts a toy in the box using the b sticker, the box with the a sticker has the toy too, because it was the same box all along. The joke is that JavaScript makes this feel mysterious, like magic science, when it is really just two names for one thing.

Level 2: Same Array, Two Names

An array is a list-like data structure. In JavaScript, [] creates a new array object. A variable like a does not contain the whole array directly; it holds a reference to where that array object lives. When the code says var b = a, JavaScript copies the reference, not the array.

So a and b are two labels for the same thing. If you use b.push(...), the array itself changes, and a sees that same changed array because a is still pointing to it. To make a separate copy, you need to clone it intentionally:

const a = [];
const b = [...a];

The meme's atom picture exaggerates this into quantum entanglement, where distant particles behave as if linked. That is the pop-culture metaphor: touch one variable, the other reacts. The real programming lesson is simpler and more useful: understand when your code is sharing data versus copying data.

Level 3: Aliased Particles

The top of the meme shows var a = [] followed by var b = a, then compares Every other language: to JS and its glowing Cyantum entaglemant. The technical joke is that b does not become a fresh, independent array. It becomes another variable pointing at the same array object. Mutate the array through one name, and the other name appears to change too, as if two tiny JavaScript atoms are sharing a suspicious beam of state.

The funniest part is also the least accurate part: this is not uniquely JavaScript. Python lists, Ruby arrays, Java objects, C# reference types, and many other languages have the same basic reference aliasing behavior. What makes JavaScript a good target is cultural: developers often meet this behavior while also juggling loose equality, object mutation, browser APIs, async callbacks, and framework state. JavaScript did not invent shared mutable references; it just made millions of people discover them at 1:17 AM inside a React component.

The real senior-level pain is not var b = a in a toy snippet. It is the production version where a helper function mutates a passed-in object, a cache returns the same array instance to multiple callers, or a state reducer accidentally edits nested data in place. Once two pieces of code share the same mutable object, ownership becomes fuzzy. Who is allowed to change it? Who assumes it stays stable? Which test only passes because execution order happened to be friendly today?

const a = [];
const b = a;

b.push("surprise");

console.log(a); // ["surprise"]

That is not quantum physics. It is one object, two references, and the usual invoice from mutable state.

Description

The meme shows large code text at the top: "var a = []" and "var b = a". Below it, the left side says "Every other language:" next to a diagram of two separate atom-like structures divided by a red vertical line, while a yellow "JS" logo introduces a colorful lower panel labeled "Cyantum entaglemant" with two glowing atoms connected by an energy beam and a blank mannequin face. The joke claims that assigning one JavaScript array variable to another creates spooky linked behavior, because both variables reference the same mutable array object. Technically, this is reference aliasing rather than JavaScript-specific quantum weirdness, and many object-oriented or dynamic languages behave similarly.

Comments

1
Anonymous ★ Top Pick The scary part is not JavaScript; it is a mutable alias crossing a module boundary with no one owning the invariant.
  1. Anonymous ★ Top Pick

    The scary part is not JavaScript; it is a mutable alias crossing a module boundary with no one owning the invariant.

Use J and K for navigation