Search code examples
javascriptminifyuglifyjs

Javascript minification why is false replaced with !1 and true with !0


I'm writing an app using Enyo2 which comes with a minification tool based on UglifyJS. I've noticed that:

var t = false

is replaced with

var t=!1

The same way true is replaced with !0. I'm sure there is a good explanation for that, I just can't find it. Any idea?


Solution

  • There is one apparently. If you use 1 or 0 to translate true or false, it would be shorter but seen as integers. If you add ! in front and reverse them, it will be coalesced into booleans and still be short.