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 javascript compares whether strings are equal

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

Share

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

This article mainly introduces javascript how to compare whether the string is equal, the article is very detailed, has a certain reference value, interested friends must read it!

Javascript compares whether the string is equal: 1, use the "= =" operator for equality comparison, syntax "str1==str2"; 2, use the "=" operator for equality comparison, syntax "str1===str2".

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

Javascript compares whether strings are equal

Method 1: use "=" for equality comparison:

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

Method 2: use "=" for equality comparison

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

Extended knowledge: the difference between "=" and "= ="

"=" 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.

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

"= =" 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.

Var str1= 123456; / / Integer var str2 = "123456"; / / string alert (str1===str2); / / print out false, that is, unequal or above is all the content of the article "how javascript compares whether strings are equal". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow 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