When JavaScript is used client-side, it has to be transferred over the network, which is why we commonly minify the code, for example by removing whitespace and shortening identifiers (variable and function names, etc).
In JavaScript / ECMAScript, many functions will accept a boolean
to trigger certain behavior. For example, DOMTokenList.toggle()
or EventTarget.addEventListener()
. Using the integers 1
and 0
instead of the boolean values true
and false
, respectively, when calling upon such functions would save some additional bytes.
However, JavaScript has two comparison operators, ==
and ===
, and while 1 == true
would evaluate to true, 1 === true
would evaluate to false. Then again, maybe the standard dictates that built-in functions have to be able to deal integers when accepting a boolean or similar. In short, is it safe to replace booleans with integers in the context of built-in functions?