Javascript: if (0 =='') condition is true (note the difference between == and ===)

sponsored links
A few days ago when writing javascript script code was found to determine if statements: if (v =='') when v is 0, the result was as true, such as:
<script type="text/javascript"
if(0 == '') {
 document.write(' I love fuck, eggs  <br/>');
if(0 == false) document.write('yes'); 

Implementation of results:
I speak, eggs pain

Later if (0 == false) document.write ('yes'); is Ricki assume in dealing with different types of data == comparison, the first and then converted to a Boolean type to compare the test, but after I read the help of Javascript documents, found assumption is correct. Such as (the following excerpt from the documentation):

Equality operator (==,!=)
If the two different types of expression, is trying to convert them to strings, numbers, or Boolean quantity.
NaN and including itself does not equal any value.
Negative zero equals positive zero.
null and null and undefined are equal.
The same string, numerically equal to the number, the same object, the same Boolean value, or (when the type is not the same) can be forced into one of the above, are considered to be equal.
Other comparisons were considered not equal.

Identity operator (===,!==)
In addition to not to cast, and the type must be the same, these operators and the role of the equality operator is the same.

If the above change == === First, the results are:

Free, welcome to the red sweet potato stroll
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of Javascript: if (0 =='') condition is true (note the difference between == and ===)

  • Nan-Jing 5: When IBatis.Hibernate mixed affairs, pay attention to your SQL

    [Problem] Now, in the development of the so-called multi-storey JavaEE applications, data persistence layer is always essential, and "Automatic" of ORM - Hibernate, and "all-manual-type" of SqlMap - IBatis, equivalent data are Per ...

  • Hibernate connection pool configuration

    Hibernate connection pool configuration <! - Jdbc -> <property name="connection.driver_class"> oracle.jdbc.driver.OracleDriver </ property> <property name="connection.url"> jdbc: oracle: thin: @

  • hibernate to use the principle of

    The use of hibernate, implementation of data persistence. Has the following several processes. One configuration database connection information. Hibernate.config 2 configuration mapping. 3 use: the use of the process are the following steps: 3.1: Ge ...

  • hibernate generic generic DAO

    package org.lzpeng.dao; import; import java.util.List; import org.hibernate.Criteria; import org.hibernate.Query; import org.hibernate.criterion.Criterion; import org.springside.modules.orm.hibernate.Page; /** * * @version 2009-1-10 *

  • Java technology: Eclipse explain the use of techniques

    Editor settings: Window -> Preferences -> Java-> Editor appearance: Display line number, emphasizing symmetry shown in square brackets, to emphasize that the existing line to show Print Margins its check, Tab width set 4, print made from the fiel

  • Struts2 + hibernate + spring problem user log in

    dao layer services layer action jsp <tr> <td align="center"> <b> user name: </ b> </ td> <td> <s: textfield name = "czyNumber" cssClass = "textstyle" theme = "simple" size = &q

  • Based on JDBC, JPA Annotation achieve simple CRUD Generic Dao

    The origin of ideas are pretty long history of reasons: [Use iBATIS history] The use of iBATIS has been a long time, the system is to use the CRUD template tool to generate the code, although there are tools to generate, but looked at a lot of CRUD the Sq

  • Hibernate secondary cache

    Hibernate cache: 2-bit cache, also known as process-level cache or SessionFactory level cache, secondary cache can be shared by all of the session Cache configuration and the use of: Will echcache.xml (the document code in hibernate package directory ...

  • Hibernate's lazy strategy

    hibernate Lazy strategy can be used in: <class> tag, it can be true / false Tags can <PROPERTY> values true / false type of necessary tools to enhance <set> <list> can tag values true / false / extra <many-to-one> <on ...

blog comments powered by Disqus
Recent Entries
Tag Cloud
Random Entries