JavaScript basic concept C-true and False

Source: Internet
Author: User
  • True and False

Very similar to C and C + +, but unlike Java, JS is considered a wide range of true or false. All objects (except for empty strings) and non-0 numbers are treated as true. An empty string, 0, NULL, and undefined are treated as false.

Undefined is a special value. All variables that are not assigned any value are undefined. Clear? :) again, all functions that do not return a value actually return undefined. In fact, it is a key word. Therefore, the following code is valid:

var a = undefined;

Actually, it's similar to the following.

var A;

  • Strong value Turn

In JS, when you try to use the value to do something impossible, JS will try to make them compatible and output some meaningful results.

For example:! 0 is actually a Boolean type of true,! It is generally only used with Boolean. ' 2 ' * 1 is actually the number 2, because * cannot be used on a string. However, ' 2 ' + 1 is string 21 because the number is coerced to a string because of the existence of a string.

There's a little suggestion. You can use –var HasChildren =!!  Children.length; This sets the HasChildren to the appropriate Boolean value.

JavaScript basic concept C-true and False

Related Article

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.