background

One day, happy ready to go off work, thinking that will be a barbecue or kanto cooking, to soothe the body of a busy day, suddenly:

  • QA: Don’t go, there is a bug, the page value is showing null!
  • Me: Impossible, I specially handled!
  • QA: See for yourself!
  • Me: Wow! Indeed it was!

Confused, I opened the computer again and began to investigate one by one:

  1. Looking at the code, the null value is indeed handled
  2. Looking at the submission record, the code also pushed
  3. Check the deployment pipeline. The test environment is already deployed
  4. I cleaned out the browser cache, and the bug is still recurring

Touched I also not too high hairline, tell yourself, things do not panic, what big scene did not see.

The problem

Look at the interface request, it does return me null; Look at the code again, is it the wrong way to handle?

// Buggy code
<span v-if="num >= 0">{{ num }}</span>
Copy the code

Debug in the console I wrote a judgment condition, stunned! Boy, NULL got through the game right under my nose

null> =0 // true
Copy the code

So I didn’t give up and tried again

null= =0 // false
null > 0 // false
Copy the code

Two false together make true. Two false together make a positive.

The problem is still not that simple

Implicit conversion? A noun comes to mind. The rightness

Number(null) / / 0
Copy the code

Ah, it makes sense that null >= 0 is true. Null == 0 is false.

From what I’ve learned, null == 0 implicitly converts as well.

A look at the data reveals that this is not the case. Null is compared to 0 and returns false directly, without any implicit conversion

Reference:Non strict equality judgment

But in NULL >= 0, NULL is implicitly converted to Number(null) and then compared to 0

Reference: greater than or equal to judgment