Many JavaScript/JScript developers use Google Closure Compiler to compile their code. Even though this tool is a great way of minifying JavaScript code, believe it or not, it doesn’t always work (at least as of May 14, 2012). The following JavaScript code works fine when you run it without being minified:

function b() {
  return a--;

var a = 1;
alert(b() < !--a);​  // false

Unfortunately, the following minified code presents an issue:

function b(){return a--}var a=1;alert(b()<!--a);

Due to the “<!--” character sequence being present, the JavaScript code never runs. In order to fix the issue, it is requested that no characters be taken away. The functionality of the function should not be changed. No parentheses or brackets should be added. In addition, only a max of three bytes can be added. With the aforementioned criteria in mind, how can you modify the code to make it work after it has been run through the Google Closure Compiler?

The answer to this Problem of the Week can be found here.

1 Comment

POW Answer – Fixing Compilable JavaScript Code | Chris West's Blog · May 29, 2012 at 6:41 PM

[…] Post navigation ← Previous […]

Leave a Reply

Your email address will not be published. Required fields are marked *