While working with minified Jquery I noticed multiple statements concatenated by commas.
For Example
event.preventDefault();
event.stopPropagation();
jQuery.event.trigger( event, data, this[0] );
return event.result;
minified to:
c.preventDefault(),c.stopPropagation(),d.event.trigger(c,b,this[0]);return c.result
I did see a similar question : JavaScript variable definition: Commas vs. Semicolons
But in this case, obviously there is no performance benefit or reduction of characters.
Could I assume it was just a matter of choice for the minification script to do so?
Wouldn't it have been more safe to go with semicolon in the first place.. and prevent the overhead of the logic which avoided concatenation of commas in case of the return statement.
Minifiers tend to favour commas where possible because it allows things like if
statement bodies to be shortened. For example:
if (x) {
y = 10;
z = 20;
}
The above can be minified using a comma to remove the curly braces (since they are optional if the if
statement body is only a single statement):
if (x) y = 10, z = 20;
In cases like this it does result in shorter code, which is what minifiers are aiming for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With