What is the meaning of exclamation mark in JavaScript

青灯夜游
Release: 2021-12-08 16:35:23
Original
5385 people have browsed it

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.

What is the meaning of exclamation mark in JavaScript

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
Copy after login

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!