A JavaScript challenge for Nordic.js

Today and yesterday I’ve been visiting Nordic.js, a Scandinavian JavaScript conference. To celebrate the occasion I made a little JavaScript challenge that I announced at Twitter:


I had a specific solution in mind, which I didn’t receive, but I got a load of other solutions instead:

The first one was from Andreas Madsen and it was in line with what I was looking for: changing the text between /* and */.


Then Jonas Magazinius bent the rules (rules that only existed in my mind) with this “feature flag” solution:


This was Mathias Bynens‘ first solution. It was similar to Andreas’ code, but implemented a bit differently.


From Joshua Adams ‏I got this solution that required an HTML context, but was kind of cool anyway:


Mathias sent in some more proposals, getting closer to expected solution, the second being IE 10 only if I got it right. Update: Well, that was wrong, it actually is valid JavaScript. See this page about comment syntax.



While writing this post I got this from File Descriptor, and this was on par with what I was looking for, using the JavaScript feature “Automatic Semi-colon Insertion” and line terminators in a comment:


Finally, the code I wrote that inspired this challenge.

var a = 0, b = 0;


var a = 0, b = 0;

On Twitter I wrote that I would declare the “coolest” solution the winner, and I think it’s the one from File Descriptor. Congratulations!