Reading through some code, I came across the use of !0 and !1. I realize that these are shorter ways of writing true and false.
!0 === true
!1 === false
This of course save a few bytes, but is there some other reason to use it?
Is there a name for this way of writing it?
Most JavaScript minification tools, like UglifyJS, generate that code because it’s shorter and semantically equivalent. For example, given:
UglifyJS will generate
var x=!0;x&&alert(x).Usually, you don’t need to write code using that style; let the minifiers do their work :-).