Thanks to Adrià Tormo for sharing their work on Unsplash.

How to hold strings by reference in JavaScript

JavaScript strings are held by value, and behave exactly like any other primitive. This means that each time we slice a string, we actually occupy extra memory slots. Although this trade off makes coding more comfortable and a whole lot easier, it’s very inefficient in memory:

  • Their lengths are pre-defined in advance and cannot be changed or exceeded.

Eytan is a JavaScript artist who comes from the land of the Promise(). His hobbies are eating, sleeping; and open-source… He loves open-source.