JQuery use return! 1 or refund! 0

I see a lot of use !0and !1the source code jQuery and JS-telerks. Most of all, I saw this in return statements that could affect its use.

What is the purpose? Is this some kind of optimization?

Kendo example

+4
source share
2 answers

This is a trick to minimize:

!0 === true
!1 === false

It just does the same with fewer characters.

+5
source

I assume that technically this is optimization, but not the one that I recommend you do manually. a minifier will do it for you.

It just returns a boolean value.

!0 == true // because 1 is true, 0 is false, so NOT 0 is true.
!1 == false // same as above logic but flipped.
+1
source

Source: https://habr.com/ru/post/1615438/


All Articles