JavaScript Boolean expressions determine the conditions

2010-07-31  来源:本站原创  分类:Web  人气:142 

In JavaScript, as a judge for a separate type of an expression in if (aaa) the conditions of such judgments will be first converted to boolean aaa true or false, then judge the true and false. Other Boolean type conversion rules are:

Only define unassigned variable var aaa, its value is  undefined, In order to  false.
 String  : The empty string "" is converted to a Boolean type  false, Other  true:
 Digital  : The number 0 converts to the Boolean value is  false, Other  true:
 Object  : Null object is converted to a Boolean as  false, Other  true:
 The object property values  : Undeclared attribute value for the property value.  0 Or an empty string "" or  false Or null  , Convert Boolean values to false, the rest is  true:

The number used to judge the condition of == expression if (aaa == bbb) and if (aaa) of the situation, the following are a few examples of error-prone:

var a = "";
if(a==0){
        alert(" Empty string == 0 is true  ");// Print
}
if(0==a){
        alert("0== An empty string is true  ");// Print
}
if(0){
        alert("0 true");
}else{
        alert("0 false");// Print
}
var v = 0;
if(v){
        alert(" A variable of a value of 0   true");
}else{
        alert(" A variable of a value of 0   false");// Print
}
if(v==false){
        alert("0==false True  ");// Print
}

var obj = new Object();
obj.aa = 0;
obj.bb = false;
if(obj.aa){
        alert(" Object property value is  0 true");
}else{
        alert(" Object property value is  0 false");// Print
}
if(obj.bb){
        alert(" Object property value is  false true");
}else{
        alert(" Object property value is  false false");// Print
}

if(obj.aa==obj.bb){
        alert(" Shock  ");// Print
}
if(obj.bb==0){
        alert(" Shock  ++");// Print
}
if(obj.bb==""){
        alert(" Shock  ++");// Print
}
相关文章
  • JavaScript Boolean expressions determine the conditions 2010-07-31

    In JavaScript, as a judge for a separate type of an expression in if (aaa) the conditions of such judgments will be first converted to boolean aaa true or false, then judge the true and false. Other Boolean type conversion rules are: Only define unas

  • JavaScript Boolean Object Reference Manual prototype property 2009-04-13

    JavaScript prototype property Return JavaScript Boolean Object Reference Manual (directory) The definition and use of prototype property can be added to the object properties and methods. Grammar booleanObject.prototype Followed. Ways of or (. Proper

  • javascript regular expressions review 2009-10-21

    JS made a recent project, have seen things that basically do not remember that the Internet is to find some information on the record about. Javascript regular expression of a basic knowledge of 1 javascript regular object creation and usage Javascri

  • Ibatis3 in the if test to determine the conditions inside the analytic problem 2010-02-08

    Ibatis3 encountered a problem today, sql inside if a variable of type String in the right to write to judge the conditions are as follows: <if test="userYNFlag =='Y'"> AND use_yn = 'Y' </ if> Is always wrong, throws NumberFormatExcep

  • The use of JavaScript regular expressions 2010-04-21

    The use of JavaScript regular expressions: var phone = document.getElementById("phone").value; var reg=/^([0-9])$/g ; if(phone.length<1 || phone.length>18){ return false; }else{ return reg.exec(phone); // If the match to return matching va

  • Core Series JavaScript regular expressions in Chapter 6 2010-04-27

    Chapter VI of the regular expression Regular expression is a string formal description of the structure is very simple and beautiful, but is very powerful. Many languages have different levels of support for regular expressions, and in many a text ed

  • javascript regular expressions commonly used Methods 2010-11-18

    Regular expression method: test (), exec () String object methods: match (), search (), replace (), split () test () method: Usage: regexp object instance. Test (string) Return value: if the given object instance regexp regular rules, returns true, o

  • Commonly used in JavaScript regular expressions to verify 2009-07-01

    The correct format: "01" "09" and "1" "31." Chinese characters matching the regular expression: [u4e00-u9fa5] Matching double-byte characters (including Chinese characters included): [^ x00-xff] Blank lines matching

  • struts2 upload files, JavaScript files to determine the size of 2010-12-14

    Project: Use Ext, FormPanel, in formpanel which define a Ext.ux.form.FileUploadField (provided by the ExtJS an official upload components). The use of commons-fileupload.jar server for file upload with Struts2. commons-fileupload initial state the ma

  • Javascript Boolean.Nnumber.String 强制类型转换的区别详细介绍 2014-05-17

    我们知道 Boolean(value) 是把值转换成Boolean类型,Nnumber(value) 是把值转换成数字(整型或浮点数),而 String(value) 是把值转换成字符串,需要的朋友可以了解下 下面就来详细说一说 Javascript 中 Boolean.Nnumber.String 强制类型转换的区别. 我们知道 Boolean(value) 是把值转换成Boolean类型,Nnumber(value) 是把值转换成数字(整型或浮点数),而 String(value) 是把值转

  • javascript regular expressions Basic Usage 2009-03-01

    <script type="text/javascript"> window.onload = function(){ //RegExpInitialization ,gRefers to the global ,iIs case-insensitive var reg = new RegExp("cat","gi"); var exp = /cat/gi; //RegExpThe test ()Method ,The return

  • Learning JavaScript regular expressions Summary 1 - Overall summary 2010-08-13

    JS previous regular expression is also studied, but none of the system, today the system under study JS regular expressions, in fact, the regular Java and Js in the regular type of Datong Xiao Yi's. First: the overall learning reference Tutorial: w3s

  • oracle case when then determine the conditions 2010-12-10

    select (case when 1 = 1 then 1 else 2 end) from dual; select (Case when (6-4) = 1 then 1 when (6-5) = 2 then 2 else 2 end) from dual; select decode (3-1,2,1,3) from dual; Expressions 3-1, if the return value of 1 equals 2, otherwise 3

  • javascript how to determine undefine 2009-07-13

    A question of how to judge a js object is null or undefined, I summed up the look for the undefined === recommended (note the three equal sign, bt it) or the use of typeof, Why? Look at the section of Code var obj; alert (obj == null); alert (obj ==

  • javascript regular expressions in 11 numbers or a combination of multiple spaces 2010-04-21

    var reg = / ^ (\ s * \ d (11) \ s *) (2 ,}$/; document.getElementById ('btn'). onclick = function () ( var val = document.getElementById ('inputtext'). value; alert (reg.test (val)); );

  • javascript boolean judge 2010-06-29

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTEN

  • To determine the conditions of the browser 2011-01-05

    if IE mean? Below lists some common CSS HACK control statements. IF IE conditional comments as the use of notes, you can refer to that experienced users are welcome to share. <!--[ If! IE ]><!--> outside than IE can identify <!--<![ endi

  • Oracle join query and the sql statement to determine the conditions 2010-09-28

    SELECT 1 UPLOAD, 0 SHENGJI, MR.BUSI_ID, MASTER.PERSON_ID, MASTER.ACNT_ID, MASTER.ID_NUM, MASTER.NAME, MASTER.SEX, MR.MIGRT_OUT_REGION, MR.OUT_OPERA_TIME, MR.OUT_OPERA_ID, MR.IN_OPERA_TIME, MR.MIGRATE_STATE, MR.MIGRT_IN_REGION, case when MR.MIGRT_IN_R

  • Oracle stored procedure to determine the conditions of if statements 2011-08-12

    create or replace procedure Test1 (score in number) as begin if (score> 90) then begin dbms_output.put_line ('the result is A'); end; elsif (score> 80) then begin dbms_output.put_line ('the result is B'); end; end if; end; State: one for each end if

  • JavaScript to determine browser type and version 2009-06-08

    This article from: http://www.mak-s.com/200919141752.html JavaScript to determine browser type and version . maks (line-height: 150%; padding: 10px;). maks p (margin-bottom: 10px; text-indent: 2em). maks. t1 (font-size: 20px; font-weight: bold;). mak