The following small series will provide you with a detailed explanation of the JS three-object calculation (ternary calculation) method. I think this is quite good. Now I will share it with you and give you a reference. Let's take a look at it with xiaobian.
1. What is a three-object operation:(Boolean expression? Value 0: value 1 ;)
5> 3? Alert ('5 da'): alert ('3 da ');
That is, if (5> 3) {alert ('5 da')} else {alert ('3 da ')};
Note: The three-object operation and the if () {} else {}The difference is that the three-object operation has a return value.
For example:
Var max = a> B? A: B;
2. How to Write the multi-condition three-object operation:
Instance:Determine four levels of ABCD based on student scores
Var result = (SC <0 | SC> 100 )? ("Invalid score "):
SC> = 90? (""):
SC> = 80? ("B "):
SC> = 60? ("C") :( "D ");
Note:You need to consider the priority during calculation. Add "()" to avoid result errors!
3. Advantages of the Three-object operation: concise and clear
The details of the above three-view JS operations (three-element operations) are all the content that I have shared with you. I hope to give you a reference and support for PHP.
For more articles on JS three-object operations (ternary operations), please refer to the PHP Chinese website!