I've seen the Google Closure compiler do a lot of rewriting in if-clauses. For example:
if (a === 3) {…}
turns to
if (3 === a) {…}
Are comparisons faster in JavaScript, if the primitive is the first argument, or what is the reason for this?
From ReorderConstantExpression.java:
As stated by a google closure compiler contributor, the compression the code comments are referring to means gzip compression, not the actual minification "compression". The reason it can improve gzip compression is that if you have
0 === x
andx === 0
in your code, the closure compiler normalizes both of these to0 === x
, which is duplicated text and thus compresses better.Then there is also:
The unique strings are:
typeof this.
,value
,key
and== "object"
But if you reorder:
The unique strings are:
"object" == typeof this.
,value
andkey
. Less unique strings and quite a long duplicate one.