DEV Community

Discussion on: What's the Wackiest Coding Hack You've Ever Seen?

Collapse
 
darthbob88 profile image
Raymond Price

I honestly don't remember where, but I saw some code that used an array of function pointers, like

logTrue = () => console.log("It's true");
logFalse = () => console.log("It's false");
var foo = [logFalse, logTrue]
foo[+true]() //Chrome doesn't convert directly from true to 1, so have to do this to convert it.
/// "It's true"
Enter fullscreen mode Exit fullscreen mode