Asked 7 years ago
11 Jan 2017
Views 1285
yogi

yogi posted

what is use of !function() - exclamation mark before the function ?

i found many script which use !function( , exclamation mark before the function , i dont understand why it used.
twitter code to embed widget.js have used !function

<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src='//platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document,'script','twitter-wjs');</script><hr><br/>


what is use of exclamation mark before the function ? what exclamation mark before the function really do ? is that means dont run function (if ! used for not operator ) or something else use of it ?
Rasi

Rasi
answered Nov 30 '-1 00:00

!function means make negative to returned value .
it is work as like ! negative operator work .
as like

!true = false

! do same for function 's return value .


function d(){return true;} 
alert(!d());/return false



Post Answer