Is the following code valid?
function test() {
return /\//.exec("\/");
}
alert(test());
It seems that many javascript minifiers (including jsmin at http://jscompress.com/) consider the “//” on the second line to be the start of a comment. I assume it’s a bug in the “trivially” implemented minifiers, since all the browser implementations I tried run it without a problem. Try it on jsfiddle.
I was interested in looking it up in the specs, and according to it it is valid:
The
\/is considered aRegularExpressionBackslashSequence, and hence is part ofRegularExpressionBody, and as a result cannot be part of the//comment marker.