日期:2014-05-16  浏览次数:20334 次

[总结] Javascript Boolean运算值测试

测试脚本

<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 : " + !!_stri