Get the App
SLTechnology News&Howtos  ›  Development  › 

What Boolean operators are there in javascript

Shulou Source: shulou.com Published: 2022-06-03 10:56:18 10月18日 Update

Xiaobian to share with you what Boolean operators in javascript, I believe most people do not know how, so share this article for your reference, I hope you have a lot of harvest after reading this article, let us go to understand it!

When making logical judgments, Boolean operators will inevitably be used. This article brings you three Boolean operators in javascript. Let's take a look at them together.

1. Logic is NOT! Implicit conversion, equivalent to negating Boolean(a).

We can get through! a to implicitly convert a to Boolean (equivalent to explicitly converting Boolean(a))

Logic and && must both be true to return true.

If (a) { console.log(1); } can be simplified to a && console.log(1);

3, logical or|| Either way, it returns true. Often used to set defaults for null or undefined data.

let a = obj.a ||'default';(ES6 can be defaulted by deconstructing assignments)

examples

if (res.names) { res.names.map(..);} It can be simplified to result.name && result.names.map (item => item.name). The above is "What Boolean operators are in javascript". All the contents of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!

Tags: Boolean operator logic article content can pass inevitable not much branch single at the same time most instance form effect data time more see knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker NVidia MariaDB Shulou Technology Linux