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

How javascript converts data to Boolean values

2025-04-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article will explain in detail how javascript converts data into Boolean values. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have some understanding of the relevant knowledge after reading this article.

Javascript data into Boolean methods: 1, the use of dual logic is not, syntax "!! need to convert the value"; 2, the use of Boolean () function, the syntax "Boolean (value to be converted)".

The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.

There are two common ways to convert a value to a Boolean value, as described below.

1. Use dual logic not

A logical non-operator! A value can be converted to a Boolean value and reversed, and two logical non-operators can convert the value to the correct Boolean value.

Console.log (! 0); / return falseconsole.log (! 1); / / return trueconsole.log (!! "); / / return falseconsole.log (!! NaN); / / return falseconsole.log (!! null); / / return falseconsole.log (!! undefined); / / return falseconsole.log (!! []); / / return trueconsole.log (! {}); / / return trueconsole.log (!! function () {}) / / return true

two。 Use the Boolean () function

Use the Boolean () function to force a value to be converted to a Boolean value.

Console.log (Boolean (0)); / / return falseconsole.log (Boolean (1)); / / return true about how javascript converts data to Boolean values. I hope the above content can be helpful to everyone and learn more knowledge. If you think the article is good, you can share it for more people to see.

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