The content of this article is about the meaning of adding !, ,-,~, ; symbols in front of JavaScript functions. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you. help.
! Negate the true and false of the return value
console.log(!function() { return; }()); // true undefined属于false, console.log(!function() { return "a"; }()); // false 字符串a属于真
, - is a mathematical operation on the return value
console.log(+function() { return 5.1; }()); // 5.1 console.log(-function() { return 5.1; }()); // -5.1
~ Perform a bitwise negation of the return value (all positive The bitwise negation of an integer is the negative of 1. The bitwise negation of all negative integers is the absolute value of 1. The bitwise negation of zero is -1)
console.log(~function() { return 5; }()); // -6 console.log(~function() { return -5; }()); // 4 console.log(~function() { return 0; }()); // -1 console.log(~function() { return "5"; }()); // -6 按位取反也会对返回值进行强制转换,将字符串5转化为数字5,然后再按位取反
; is to prevent When the code is compressed, the previous code is not written; causing an error.
This article has ended here. For more other exciting content, you can pay attention to the JavaScript Video Tutorial column on the PHP Chinese website!
The above is the detailed content of Add !, +, -, ~, in front of JavaScript functions; introduction to the meaning of symbols. For more information, please follow other related articles on the PHP Chinese website!