Home > Article > Web Front-end > What is the meaning of exclamation mark in JavaScript
In JavaScript, the exclamation point "!" refers to the logical NOT operator, which is a Boolean inversion operation. It can be placed directly before the operand. The syntax is "! Operand"; "!" operation operator will convert the operand value to a Boolean value, then negate it and return it.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
In JavaScript, the exclamation mark "!
" refers to the logical NOT operator.
Operator | Name | Example |
---|---|---|
! | Logical NOT | !x means if x is not true, then it is true |
logical NOT operation!
is a Boolean negation operation (NOT). As a unary operator, it is placed directly before the operand, converts the value of the operand to a Boolean value, then inverts and returns it.
Example 1
The following lists some logical NOT operation return values of special operands.
console.log( ! {} ); //如果操作数是对象,则返回false console.log( ! 0 ); //如果操作数是0,则返回true console.log( ! (n = 5)); //如果操作数是非零的任何数字,则返回false console.log( ! null ); //如果操作数是null,则返回true console.log( ! NaN ); //如果操作数是NaN,则返回true console.log( ! Infinity ); //如果操作数是Infinity,则返回false console.log( ! ( - Infinity )); //如果操作数是-Infinity,则返回false console.log( ! undefined ); //如果操作数是undefined,则返回true
Example 2
If you perform two logical NOT operations on the operand, it is equivalent to converting the operand into a Boolean value.
console.log( ! 0 ); //返回true console.log( ! ! 0 ); //返回false
Note: The return value of logical NOT operation must be a Boolean value.
[Related recommendations: javascript learning tutorial]
The above is the detailed content of What is the meaning of exclamation mark in JavaScript. For more information, please follow other related articles on the PHP Chinese website!