[Conclusion] JavaScript Boolean operation value test

Source: Internet
Author: User
Test script

<script type="text/javascript">  <!--var _boolean_true = true;var _boolean_false = false;var _undefined;var _null = null;var _int = 10000;var _int_1 = 1;var _int_0 = 0;var _int__0 = -0;var _NaN = NaN;var _string_onestring = "onestring";var _string_empty = "";var _string_1 = "1";var _string_0 = "0";var _string_true = "true";var _string_false = "false";var _string_null = "null";var _string_undefined = "undefined";var _function = function() {};var _array_empty = [];var _array_notempty = [1,2];var _object_empty = {};var _object_notempty = {name:'yourname'};println("Boolean(_boolean_true) : " + Boolean(_boolean_true));println("Boolean(_boolean_false) : " + Boolean(_boolean_false));println("Boolean(_undefined) : " + Boolean(_undefined));println("Boolean(_null) : " + Boolean(_null));println("Boolean(_int) : " + Boolean(_int));println("Boolean(_int_1) : " + Boolean(_int_1));println("Boolean(_int_0) : " + Boolean(_int_0));println("Boolean(_int__0) : " + Boolean(_int__0));println("Boolean(_NaN) : " + Boolean(_NaN));println("Boolean(_string_onestring) : " + Boolean(_string_onestring));println("Boolean(_string_empty) : " + Boolean(_string_empty));println("Boolean(_string_1) : " + Boolean(_string_1));println("Boolean(_string_0) : " + Boolean(_string_0));println("Boolean(_string_true) : " + Boolean(_string_true));println("Boolean(_string_false) : " + Boolean(_string_false));println("Boolean(_string_null) : " + Boolean(_string_null));println("Boolean(_function) : " + Boolean(_function));println("Boolean(_array_empty) : " + Boolean(_array_empty));println("Boolean(_array_notempty) : " + Boolean(_array_notempty));println("Boolean(_object_empty) : " + Boolean(_object_empty));println("Boolean(_object_notempty) : " + Boolean(_object_notempty));println();println("!_boolean_true : " + !_boolean_true);println("!_boolean_false : " + !_boolean_false);println("!_undefined : " + !_undefined);println("!_null : " + !_null);println("!_int : " + !_int);println("!_int_1 : " + !_int_1);println("!_int_0 : " + !_int_0);println("!_int__0 : " + !_int__0);println("!_NaN : " + !_NaN);println("!_string_onestring : " + !_string_onestring);println("!_string_empty : " + !_string_empty);println("!_string_1 : " + !_string_1);println("!_string_0 : " + !_string_0);println("!_string_true : " + !_string_true);println("!_string_false : " + !_string_false);println("!_string_null : " + !_string_null);println("!_function : " + !_function);println("!_array_empty : " + !_array_empty);println("!_array_notempty : " + !_array_notempty);println("!_object_empty : " + !_object_empty);println("!_object_notempty : " + !_object_notempty);println();println("!!_boolean_true : " + !!_boolean_true);println("!!_boolean_false : " + !!_boolean_false);println("!!_undefined : " + !!_undefined);println("!!_null : " + !!_null);println("!!_int : " + !!_int);println("!!_int_1 : " + !!_int_1);println("!!_int_0 : " + !!_int_0);println("!!_int__0 : " + !!_int__0);println("!!_NaN : " + !!_NaN);println("!!_string_onestring : " + !!_string_onestring);println("!!_string_empty : " + !!_string_empty);println("!!_string_1 : " + !!_string_1);println("!!_string_0 : " + !!_string_0);println("!!_string_true : " + !!_string_true);println("!!_string_false : " + !!_string_false);println("!!_string_null : " + !!_string_null);println("!!_function : " + !!_function);println("!!_array_empty : " + !!_array_empty);println("!!_array_notempty : " + !!_array_notempty);println("!!_object_empty : " + !!_object_empty);println("!!_object_notempty : " + !!_object_notempty);function println(s) { s = s || ""; document.writeln(s + "<br/>"); }  //--></script>

Run scripts

Test Results

Boolean (_ boolean_true): True
Boolean (_ boolean_false): false
Boolean (_ undefined): false
Boolean (_ null): false
Boolean (_ INT): True
Boolean (_ int_1): True
Boolean (_ int_0): false
Boolean (_ int _ 0): false
Boolean (_ Nan): false
Boolean (_ string_onestring): True
Boolean (_ string_empty): false
Boolean (_ string_1): True
Boolean (_ string_0): True
Boolean (_ string_true): True
Boolean (_ string_false): True
Boolean (_ string_null): True
Boolean (_ function): True
Boolean (_ array_empty): True
Boolean (_ array_notempty): True
Boolean (_ object_empty): True
Boolean (_ object_notempty): True

! _ Boolean_true: false
! _ Boolean_false: True
! _ Undefined: True
! _ NULL: True
! _ INT: false
! _ Int_1: false
! _ Int_0: True
! _ Int _ 0: True
! _ Nan: True
! _ String_onestring: false
! _ String_empty: True
! _ String_1: false
! _ String_0: false
! _ String_true: false
! _ String_false: false
! _ String_null: false
! _ Function: false
! _ Array_empty: false
! _ Array_notempty: false
! _ Object_empty: false
! _ Object_notempty: false

!! _ Boolean_true: True
!! _ Boolean_false: false
!! _ Undefined: false
!! _ NULL: false
!! _ INT: True
!! _ Int_1: True
!! _ Int_0: false
!! _ Int _ 0: false
!! _ NAN: false
!! _ String_onestring: True
!! _ String_empty: false
!! _ String_1: True
!! _ String_0: True
!! _ String_true: True
!! _ String_false: True
!! _ String_null: True
!! _ Function: True
!! _ Array_empty: True
!! _ Array_notempty: True
!! _ Object_empty: True
!! _ Object_notempty: True

Conclusion

0,-0, null, "", false, undefined, Or Nan: This7Result After a Boolean operation, the result is false. Otherwise, the result is true.

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.