I came across a rather peculiar implementation of a string repeat function for JavaScript.

There's a built-in for this since ES2015, and prior to that, the following was a common idom:

> str = "x"
> count = 3
> out = (new Array(count + 1).join(str)

But, an MDN contributor thought - we can optimize this! Can you figure out how and why it works?

👉 codepen.io/Krinkle/pen/abmrLdz

A collegue of mine ran into this some interesting code behaviour today. I encountered this before, but didn't realize it was still a thing. Fun times!

Can you guess what caused the string to become an integer?

👉 3v4l.org/odIiW

Mastodon for Tech Folks

This Mastodon instance is for people interested in technology. Discussions aren't limited to technology, because tech folks shouldn't be limited to technology either!