Why does JavaScript use fewer ternary operators
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!