Skip to content

Instantly share code, notes, and snippets.

@magnetikonline
Last active December 15, 2015 15:39
Show Gist options
  • Save magnetikonline/5283391 to your computer and use it in GitHub Desktop.
Save magnetikonline/5283391 to your computer and use it in GitHub Desktop.
Google Closure JavaScript compiler optimization examples.
// a statement like this...
if (fruit == 'apples') fruit = 'bananas';
// is converted to this...
'apples'==fruit&&(fruit='bananas');
// next... a statement like this...
if (fruit !== undefined) callMe();
// is converted to this...
if(void 0!==fruit)callMe();
// truthy values
var myVariable = true;
// are converted to this...
myVariable=!0;
// pre-calculated math
var COOKIE_LIFETIME_DAYS = 30,
expireUTC = new Date();
// calculate expiry time for cookie
expireUTC.setTime(
expireUTC.getTime() +
(COOKIE_LIFETIME_DAYS * 24 * 60 * 60 * 1000) // hours * minutes * seconds * microseconds
);
// is converted to this
var b=new Date;b.setTime(b.getTime()+2592E6);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment