Somewhere in jQuery I have seen 2 functions that returns only boolean like below.
function h(){
return !0;
}
function r(){
return !1;
}
What is the purpose of doing this, while Boolean can be written directly?
Somewhere in jQuery I have seen 2 functions that returns only boolean like below.
function h(){
return !0;
}
function r(){
return !1;
}
What is the purpose of doing this, while Boolean can be written directly?
On
Economy of characters.
Having a 3 character function that returns true or false takes less characters than doing an exact comparison.
var a = false;
if (a === r()) console.log('3 characters instead of 5')
Large libraries usually alias commonly used globals like undefined and window as well for minification.
For example, you may see something like
(function($, a, b) { ... })(jQuery, window, undefined)
0is falsey and1is truthy.So, there is no need to convert them to boolean unless they are used in code like
Or code converted when the code is minified as
trueandfalseare minified to!1and!0respectively.