0

what's meaning the symbol "!" before a function ? return something different ?

one exemple : var a=5; !function (x) {a=x;}(7) alert(a);

29th Sep 2019, 12:16 PM
Oneill~Онеилл~奥尼尔~ओनील~اونیل~*‎
Oneill~Онеилл~奥尼尔~ओनील~اونیل~*‎ - avatar
3 Answers
+ 2
! is the boolean not operator, which you probably know. Calling a function results in a value (in this case undefined). The side effect still happens, so a will be assigned 7, but then nothing happens. You can rewrite it like this: a = x; !undefined !undefined is true, but since it isn't used at all, it won't matter.
29th Sep 2019, 12:21 PM
Airree
Airree - avatar
0
first thank ODLNT and Airree for your answers. I understand better. So, it was a question in JavaScript challenges... i just would understand what's happen in this case (i hope it will not use in some crazy real program code :p)
29th Sep 2019, 12:37 PM
Oneill~Онеилл~奥尼尔~ओनील~اونیل~*‎
Oneill~Онеилл~奥尼尔~ओनील~اونیل~*‎ - avatar