Get the App
SLTechnology News&Howtos  ›  Development  › 

Why does JavaScript use fewer ternary operators

Shulou Source: shulou.com Published: 2022-06-01 04:35:21 10月03日 Update

This article is to share with you about why JavaScript uses less ternary operators. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Reduce the use of ternary operators

The trinomial operator has high performance and less code.

However, ternary operators should not be abused. We should use them in simple logic branches and avoid them in complex logic branches.

/ / simple logic can use the ternary operator var global = typeof window! = = "undefined"? Window: this;// complex logic is not suitable for var ok = isString? (isTooLang? 2: (isTooShort? 1: 0)):-1; Thank you for reading! This is the end of this article on why JavaScript uses less trinomial operators. I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Operators operations logic complexity content branches more articles good practical code performance articles see knowledge references help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Linux MySQL Shulou Technology Microsoft