[X]

Plus Joins, Minus Subtracts

luljs still works

Adding a string glues it on, subtracting a string does arithmetic.

In 2026: Still works. The + operator prefers string concatenation whenever either side is a string, so "11" + 1 is "111". Every other arithmetic operator has no string mode at all, so it coerces both sides to numbers: "11" - 1 is 10.

Where it came from: The split comes from + being the only arithmetic operator with a string mode; every other one forces numbers, as MDN's subtraction page spells out. MDN

<script>
document.write("<p><code>\"11\" + 1</code> is <b>" + ("11" + 1) + "</b></p>");
document.write("<p><code>\"11\" - 1</code> is <b>" + ("11" - 1) + "</b></p>");
document.write("<p><code>\"5\" * \"3\"</code> is <b>" + ("5" * "3") + "</b></p>");
</script>
sandboxed demo · breaks nothing but itselfrestart

More in luljs

all 63 in luljs › · the whole library ›