Today, I found a very strange Js problem when I was in the company. I didn't notice before that I took out the value of a certain field from the database, and the value of this field happened to be 0. Then when I judged whether this value is equal to "", the following problem occurred:
That is, JS believes that 0=="" is true, that is, the result of 0=="" is true.
The verification code is as follows:
<script type="text/javascript">if(==""){alert('=="" result is: '+(==""));//true}if(===""){alert("true");}else{alert('==="" result is: '+(===""));//false}</script>Later, it was changed to using 0==="" to compare. The result at this time is false. It seems that in the future, you should pay attention to whether the value is equal to "" before writing the judgment value, and then make a judgment first, or use === to judge directly, and use a strict way to judge!