Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the conditional operator for javascript

2025-03-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Today Xiaobian to share with you what the conditional operators of javascript is related knowledge points, detailed content, clear logic, I believe most people still know too much about this knowledge, so share this article for everyone to refer to, I hope you read this article after harvest, let's learn about it together.

Javascript has conditional operators. In js, conditional operators are also called "ternary operators" and the syntax is "conditional expression?" Expression 1 : Expression 2 ;"; If the result of Conditional Expression is true, execute the code in Expression 1, otherwise execute the code in Expression 2.

Operating environment of this tutorial: Windows 7 system, Javascript version 1.8.5, Dell G3 computer.

Conditional operators in javascript

In javascript, conditional operators, also known as ternary operators, are the only operators that use three operands, consisting of a question mark and a colon. The syntax is as follows:

conditional expression? Expression 1 : Expression 2 ;

If the result of Conditional Expression is true, execute the code in Expression 1, otherwise execute the code in Expression 2.

execution flow

Conditional operators, when executed, first evaluate the conditional expression

If this value is true, expression 1 is executed

If the value is false, expression 2 is executed

Examples:

var a = 10;var b = 20;a > b ? alert("statement 1"):alert("statement 2")

The above is "javascript conditional operator is what" all the content of this article, thank you for reading! I believe everyone has a great harvest after reading this article. Xiaobian will update different knowledge for everyone every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report