Home>Article>Web Front-end> What is the javascript ternary operator? Introduction to the usage of js ternary operator

What is the javascript ternary operator? Introduction to the usage of js ternary operator

不言
不言 Original
2018-09-19 17:42:54 3280browse

The content of this article is about what is the javascript ternary operator? The introduction to the usage of js ternary operator has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Speaking of js, it may be quite laborious for many beginners. I also feel that my js skills are not solid enough, so I will learn some things and share them in the hope that they can be helpful. People who need

"Ternary Operator" What is the ternary operator

Conditions? Execution if the condition is true: Execution if the condition is not true;

is equivalent to a simple if()else() statement

For example:

var num=10; if(num>5 && num<=10){ num++; }else{ num--; }

Ternary operator writing method

num>5 && num<=10 ? num++:num--; 三元运算符另外一种情况,相当于只有if()的语句,改写为三元运算符写法, var num=10; if(num>5 && num<=10){ num++; }

num>5 && num944d33b9ee604817d89a2694e72cf5c45 && num<=10?(num, console.log(num)):null; Multiple statements are separated by commas

*Keywords such as break, continue, return, etc. cannot appear in the operation of the ternary operator;

The above is the detailed content of What is the javascript ternary operator? Introduction to the usage of js ternary operator. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn