Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the short-circuit condition in JavaScript

Shulou Source: shulou.com Published: 2022-06-01 04:21:47 09月22日 Update

Editor to share with you how JavaScript to achieve short-circuit conditions, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!

Short circuit condition

If you've ever seen code like this:

If (conected) {login ();}

Then you can use the & & (AND operator) between these two variables to shorten the code. For example, the previous code can be reduced to one line:

Conected & & login ()

You can also use this method to check whether there are certain properties or functions in the object. Similar to the following code:

User & & user.login (); above is all the content of the article "how to achieve short-circuit condition in JavaScript". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Code conditions articles content one line not much between two functions variables most objects properties methods more knowledge industry information channels operators Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology vpn Shulou Information MariaDB NVidia