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 are the skills of using Js

2025-04-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly talks about "what are the skills of using Js". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn what are the skills of using Js.

A probe into the Origin of the obscene skills of Js

Two years ago. I haven't graduated yet, and I chose to enter the front end in the last semester of the university. at the same time, I have to say that one of the reasons I was attracted to the front-end camp is that js is obscene and skillful. At the same time, I am a more curious person, so I learned a lot about the tricks of js.

Now these tricks and tricks have either become an integral part of the language or disappear with the passage of time, and some have unwittingly forgotten, since this article is an introduction to this area of knowledge, let's introduce some more examples from previous studies.

What are the tricks and tricks of Js?

~ operator + indexOf

Before es6includes is implemented, we can only use the indexOf method to determine that a string or array contains, but the index of the exact element returned by indexOf returns-1 if it does not exist. Because before writing the c language, we used to use 0 for success and 123 for different errors. Because 0 is unique. There is the concept of truthyfalsy in a c-like language. Does not refer to true and false of bool.

The following table represents the truthy and falsy of js.

Variable type falsy truthy

Boolean false true

String "" is not an empty string

Numeric 0NaN any number that is not falsy

Is null right?

Is undefined right?

Object (array), {} and whether [] is

For numerical values, we know that 0 is unique to numerical values, while-1 is not. Then we can change-1 to 0 through the ~ operator.

~-1

/ / 0

~ 1

/ /-2

Explain.

A NOT operation is performed for each bit. The result of NOTa is the inversion of a (i.e. inverse code).

9 (base10) = 00000000000000000000000000001001 (base2)

~ 9 (base10) = 111111111111111111111111111111110110 (base2) =-10 (base10)

Because the first bit represents the symbolic position in the computer.

At the same time, simple understanding. The result of a bitwise non-operation on any numeric value x is-(xdistinct 1). That is to say,-1 (and only-1) can be changed into falsy through ~.

At this point, I believe you have a deeper understanding of "what are the techniques for using Js?". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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: 219

*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