Get the App
SLTechnology News&Howtos  ›  Development  › 

How to abbreviate ternary operator by JavaScript

Shulou Source: shulou.com Published: 2022-06-01 04:38:40 10月04日 Update

This article mainly introduces how to abbreviate the ternary operator of JavaScript. It is very detailed and has certain reference value. Friends who are interested must finish reading it.

Ternary operator

The following is a good example of a complete if statement abbreviated to one line of code.

Const x = 20 answer;if (x > 10) {answer = 'greater than 10;} else {answer =' less than 10;}

Abbreviated as:

Const answer = x > 10? 'greater than 10': 'less than 10'; the above is all the content of the article "how to abbreviate the trinomial operator in JavaScript". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Abbreviations operators operations content articles lines codes values examples interests guys buddies more knowledge industry sentences information channels channels references Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Shulou Tech Info MySQL Redmi OPPO Reno