hello i have a one question about IIFE.
I know IIFE’s general method is
(function(){/code/})()
however, recently i found a new method about IIFE
!function(){/code/}() and +function(){/code/}
is also works like IIFE
i think first is ! make value bool, so the code is to true()?
and second + is make value number and that code is trans NaN()?
but two codes(true(),NaN())not working and two new type IIFE works well
i know how that two codes work IIFE please tell me the
procedure
>Solution :
In the cases of !function() {}() and +function() {}() JavaScript will first evaluate the right handside of the given statement/IIFE and then cast the return value of the IIFE to a boolean in case of ! or to type number in case of +.
If the IIFE returns a boolean ! will negate the return value.
Example
console.log(
!function() {
return "something";
}()
);
/**
!function() {
return "something";
}()
evaluates to
!"something" and not true() or false()
lastly !"something" is equivalent to false
*/