js The AND-OR operator || && is wonderfully useful and can be used to streamline code and reduce the readability of the program.
Requirement 1.
Assume that the growth speed display regulations are as follows:
When the growth speed is 5, 1 arrow is displayed;
When the growth speed is 10, 2 arrows are displayed;
A growth rate of 12 displays 3 arrows;
A growth rate of 15 displays 4 arrows;
Others display 0 arrows.
How to implement it with code?
Requirement 2.
Assume that the growth speed display regulations are as follows:
##The growth speed is >12 and 4 are displayed Arrows;
When the growth rate is >10, 3 arrows are displayed;
When the growth rate is >5, 2 arrows are displayed;
The growth rate is >0 and 1 arrow is displayed;
The growth rate is <=0 and 0 arrows are displayed.
Then it is very troublesome to implement it with switch.
So have you ever thought about implementing it in one line of code?
ok, let’s take a look at the powerful expressiveness of js:
00669a79fa5f8805c2d839c5fd0ee8f6
Maybe you also discovered that another very clever thing about the author is !tags.indexOf("
The above is the detailed content of Detailed explanation of usage techniques of javascript operators || and &&. For more information, please follow other related articles on the PHP Chinese website!