Get the App
SLTechnology News&Howtos  ›  Development  › 

How js uses logical operators

Shulou Source: shulou.com Published: 2022-06-01 05:55:27 09月28日 Update

This article mainly introduces how js uses logical operators, which has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to understand it.

Use logical operators

If there is a piece of code like this:

If (a > 10) {doSomething (a)}

You can use logical operators to override:

A > 10 & & doSomething (a)

This makes it much simpler to write, and if the value preceding the logic and the & & operator is false, a short circuit occurs, directly ending the execution of this sentence; if true, the code that follows & & continues and returns the return value of the later code. Using this approach can reduce a lot of if...else judgments.

Thank you for reading this article carefully. I hope the article "how to use logical operators in js" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Logic operators operations articles code simplicity value interest at the same time operators ways more friends knowledge ribbons industry information information channels channels references Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology MariaDB Redmi Shulou Information Shulou Tech Info