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 does javascript determine that strings are not equal?

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

Share

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

This article mainly introduces "how to judge string unequal by javascript". In daily operation, I believe that many people have doubts about how to judge string unequal in javascript. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubt that "javascript how to judge string unequal". Next, please follow the editor to study!

Js to determine the string is not equal to the method: 1, using the "= =" equality operator, syntax "string 1 = = string 2", equality returns true, inequality returns false;2, using the "= =" identity operator, syntax "string 1 = string 2", equality returns true, and vice versa.

The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.

Javascript determines that strings are not equal.

In javascript, you can use the "= =" or "=" operators to determine that strings are not equal.

1. Use "=" to make an equal comparison:

Examples

Var str1= "123456"; / / string var str2 = "123456"; / / string alert (str1==str2); / / print out true, that is, equal

2. Use "=" to make an equal comparison:

Examples

Var str1= "123456"; / / string var str2 = "123456"; / / string alert (str1==str2); / / print out true, that is, equal

Description: the difference between "=" or "= =" operators

"=" means "equivalent" and type conversions of the necessary values are performed before equality comparisons are made. To put it simply, it is to convert the value to the same type before making an equal comparison. Even if the type of the compared value is different, it can be cast to the same type without error.

"= =" means "identity" and no type conversion is performed, so if the two values are not of the same type, it returns false when compared. If you compare two variables whose types are not compatible with each other, a compilation error will occur.

Example 1

Var str1= 123456; / / Integer var str2 = "123456"; / / string alert (str1==str2); / / print out true, that is, equal

Example 2

Var str1= 123456; / / integer var str2 = "123456"; / / string alert (str1==str2); / / print out false, that is, it is not equal to this, the study on "how javascript determines that strings are not equal" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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