Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the skills of using Js

Shulou Source: shulou.com Published: 2022-06-02 15:43:15 09月12日 Update

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!

Tags: Stunts numerical values stunts representatives skills at the same time language learning content front ends characters strings arrays methods results or operators operations deeper unwittingly Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Shulou Information macOS NVidia OPPO Reno