Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

what is javascript IIFE principle

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

!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
*/
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading