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 is the difference between JavaScript and TypeScript

2025-03-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

Most people do not understand the knowledge points of this article "JavaScript and TypeScript = = and =", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "JavaScript and TypeScript in = and = = what is the difference" article.

Come to a conclusion first

For basic types such as String and number, the = = operator first casts the variables on both sides to the same type and then compares whether they are equal; the = = operator does not cast the type, but makes a direct comparison.

For advanced types such as array and object, there is no difference between = and =, because they compare "pointer addresses".

For the basic type and the advanced type, there is a difference between = = and =; the = = operator will first convert the advanced type to the basic type and then compare the values; the = = operator will not convert and return false directly if the type is different.

In other words, the `= =` operator only needs to compare whether the values of the two variables are equal, while the `= =` operator requires that the values and types of the two variables be the same; similarly, the `! =` operator will cast the type, while the `! =` operator will not convert the type.

Let's write a code example of a base type variable:

66 ='66'; / / return true66 ='66'/ / return false

The = = operator converts the string in the first line into a number, compares it with 66, and the value is equal, so the true;=== operator returns no type conversion, because the number on the left and the string on the right are of different types, and false is returned.

Note that for the special value NaN (Not a Number), which means that it is not a number, false will be returned if NaN is compared with any number (including itself), so it is best to use the isNaN () function to judge NaN.

For undefined and null, a comparison of their values returns true.

The code example is as follows:

NaN = = 6; / / return falseNaN = NaN; / / return falsenull = = undefined; / / return truenull = undefined; / / return false

Finally, because the implicit type conversion rules brought about by the = = and! = operators are very cumbersome, and to avoid bug caused by data type confusion, it is recommended to use the = = operator and the! = = operator.

When comparing js, if it is = =, it will convert the type first, and then determine the value. If it is =, the type and value must be equal.

The above is about the content of this article on "what is the difference between JavaScript and TypeScript?". I believe we all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please pay attention to the industry information channel.

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