Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What does the exclamation point mean in JavaScript

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report