Get the App
SLTechnology News&Howtos  ›  Development  › 

How JavaScript simplifies if... Else

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

Editor, let's share with you how JavaScript simplifies if. Else, I believe that most people do not know much about it, so share this article for your reference. I hope you will learn a lot after reading this article. Let's learn about it together.

Simplify if... Else

If...else is so common that many people forget that there are other ways to judge conditions. For example, for a simple variable assignment, there is no need to use such a lengthy statement, and one-line expression is done:

/ / novice let test= boolean; if (x > 100) {test= true;} else {test= false;} / / abbreviated expression let test= (x > 10)? True: false; / / more direct let test = x > 10; console.log (test)

Ternary expressions can make complex conditional bifurcation judgments, but at the expense of some readability:

Let x = 300, let test2 = (x > 100)? 'greater 100': (x < 50)? 'less 50': 'between 50 and 100'; console.log (test2); / / "greater than 100" JavaScript is the abbreviation of JavaScript, it is a literal scripting language, its interpreter is called JavaScript engine, is a part of the browser, mainly used for web development, can add a variety of dynamic effects to the website, make the page more beautiful.

The above is all the contents of the article "how JavaScript simplifies if... else". 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: Articles expressions content conditions lengthy complex necessary beautiful one line not much writing branching dynamics variables readability various most engines effects novice Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Redmi Shulou Information OPPO Reno MySQL