Home > Web Front-end > JS Tutorial > Detailed explanation of usage techniques of javascript operators || and &&

Detailed explanation of usage techniques of javascript operators || and &&

伊谢尔伦
Release: 2017-07-19 09:16:08
Original
1325 people have browsed it

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

This code is used by the author to process $(html), some tags must be constrained, such as < ;option> must be within .

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template