Special case where the variable value is 0 when judging variables in JavaScript

Source: Internet
Author: User

Sometimes we will directly determine the value of the variable in JS, here are a few things:

 var  a = 0;  var  b = 1;  var  c = ' 

In the above case we c,d have no value, so the result is null, but the value of a is 0, the result is also null, here is a special case, 0 in JavaScript judgment is false, so here the result is null, Therefore, we should consider this situation when we make the variable judgment, lest the value of the variable is 0 o'clock, the code in the previous project is judged here, resulting in a variable of 0 being assigned to NULL, the result of this parameter is not passed in, resulting in a program error.

Special case where the variable value is 0 when judging variables in JavaScript

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.