Search code examples
javascriptredefinition

What are squishable variables?


I was reading some javascript code from a project I inherited and found this:

// Declare squishable vars
var TRUE = true, 
    FALSE = false, 
    NULL = null;

I don't understand what the developer means by squishable and why it would be desirable to alias these built-in values.

Is there a good reason to do this?


Solution

  • Supposedly "squishable" here means minifiable. Built-in constants cannot be substituted or minified, since false has a defined meaning in Javascript. However, any arbitrary variable name can be substituted by any other arbitrary variable name. Minifiers use this fact to make code shorter and substitute all variables names for a, b etc. If you're using false literals a lot, this can easily make a difference of a few kilobyte.