The last one works because “new RegExp({})” becomes “/[object Object]/” which would be more normally written like “/[bcejOot ]/”. With the split and join, it acts more like s/[^bcejOot ]//g

Want to try any of theses out? In Chrome, just open the Javascript console (Ctrl-Shift-J in Windows) and paste the JS expressions.

Originally shared by Colin McMillen

Ladies, gentlemen, and JavaScript hackers of the world, I present to you:


[“3”, “6”]

From which a co-worker came up with:

>”30456″.split(new RegExp(1/2))

and one more step across the brink of madness:

>”ToInfinityCanadaAndBeyond”.split(new RegExp(1/0))

And hey, why not:

>”bees bit one foot; cute blob!”.split(new RegExp({})).join(“”)

#DynamicTypingIsBestTyping   #JavaScript   #wat