How js uses logical operators
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!