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

How to use the & & operator and the | | operator in javascript

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article shows you how to use the & & operator and the | operator in javascript. The content is concise and easy to understand, which can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Preface

In the field of front-end development, the & & operator and the | operator are highly utilized and frequently used.

The & & operator and the | | operator are so powerful that it is essential to be a good front-end engineer.

But many front-end engineers (beginner rookies [including Xiaobian itself]) are extremely underutilized of the & & operator and the | operator.

We have never used it before when developing some projects in school, because we are already bound by traditional concepts. Here's how we understand the & & operator and the | operator.

& operator

The result is true when the result on the left and right of the & & operator is true at the same time.

When the result on the left and right of the & & operator is both false, the result is false.

When one of the results on the left and right of the & & operator is false, the result is false.

Conclusion: the same truth is true, otherwise it is false

| | operator |

| the result on the left and right of the operator is true, and the result is true. |

| | if one of the results on the left and right of the operator is false, the result is true.

| | if the result on the left and right of the operator is false at the same time, the result is false.

Summary: the same false is false, otherwise it is true

But is that really the case? Let's take a look at the little demo about the & & operator

Let result=1&&2; console.log (result)

Do you want to return to true as a result? At the beginning is also the same as you, but in the study practice, not so, here please allow Xiaobian to make a small advertisement, colleagues can be in Tencent classroom or bilibili search to take an education, conscience recommendation, said that the teacher inside the lecture is very excellent, interested peers can try, too far, we return to the topic, in fact, the result is 2.

| | small demo of operator |

Var result=1 | | 0 console.log (result)

Results:

Are you surprised? Oh, my God! To my surprise, the return value of the two results is not true or false, and the editor has nothing to do with you. Let's get down to business.

Objectives of this chapter

Learn to use the & & operator and the | operator

Strengthen the understanding of the & & operator and the | operator through cases.

Case practice (by loading json render data)

# myTab {width: 800px; margin: 0 auto } number, name, price status / / 0 means to be paid, 1 means paid, 2 means received 3 represents other var orderArray= [{id:10001, name:' Xiaomi 9, price:1999, status:0,}, {id:10002, name:'huaweiPro', price:2999 Status:1,}, {id:10003, name:' Xiaomi 8X', price:999, status:2,}, {id:10004, name:' Honor 8X' Price:1399, status:3,}] $("# myTab tr:not (: eq (0))"). Remove (); for (var item0)

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