What does the exclamation point mean in JavaScript
This article mainly introduces what the exclamation mark means in JavaScript. It has a certain reference value. Interested friends can refer to it. I hope you can learn a lot after reading this article. Let's take a look at it.
In JavaScript, the exclamation point "!" Refers to the logical non-operator, is a Boolean inverse operation, directly before the Operand, syntax "! Operand"; "!" The operator converts the value of the Operand to a Boolean value, which is then reversed and returned.
The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.
In JavaScript, the exclamation point "!" Refers to logical non-operators.
Example of an operator name! Logic is not! X means that if x is not true, it is true.
Logic is not arithmetic! Is a Boolean inversion operation (NOT). As a unary operator, it is placed directly before the Operand, converting the value of the Operand to a Boolean value, then inverting it and returning it.
Example 1
The logical non-operation return values of some special operands are listed below.
Console.log (! {}); / / return falseconsole.log (! 0) if the Operand is an object; / / return trueconsole.log (! (n = 5)); / / returns falseconsole.log (!) if the Operand is any number that is not zero. Null); / / if the Operand is null, return trueconsole.log (! NaN); / / if the Operand is NaN, return trueconsole.log (! Infinity); / / return falseconsole.log (! (- Infinity)) if the Operand is Infinity; / / return falseconsole.log (!) if the Operand is-Infinity Undefined); / / return true if the Operand is undefined
Example 2
If you perform two logical non-operational operations on an Operand, it is equivalent to converting the Operand to a Boolean value.
Console.log (! 0); / / return trueconsole.log (! 0); / / return false
Note: the return value of a logical non-operation must be a Boolean value.
Thank you for reading this article carefully. I hope the article "what is the exclamation mark in JavaScript" shared by the editor is helpful to everyone? at the same time, I also hope that you can support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!