Hello :)

if you test this code you can understant easily this feature :

1 - first example

var a = "toto" ;

var b = (a != undefined) ;

if ( b )
{
    trace("a exist : " + a) ;
}

2 - second exemple

var a = "toto" ;

if ( a )
{
    trace("a exist : " + a) ;
}

You can show the variable a in a conditional expression corresponding with
the "true" value... if the variable is undefined in a conditional expression
the variable is false !

3 - New example :

function test1 ( message )
{
     if (message == undefined)
     {
           message = "empty" ;
     }

    return message ;
}

trace( test1() ) ;

function test2 ( message:String )
{
     if ( !message )
     {
           message = "empty" ;
     }

    return message ;
}

trace( test2() ) ;

function test3 ( message:String )
{

    message = (message || "empty") ; // if message != undefined ... message
is true the || return message else.. || return "empty"
    return message ;
}

trace( test3() ) ;

function test4 (message:String )
{
    return  (message) ? message : "empty" ; // if message exist and is
true... return message else return "empty"
}

trace( test4() ) ;

...

in a conditional expression, an object used true or false value and not the
primitive value ;) if you use == or < or > or != the variable primitive
value is used...

EKA+ :)




2006/12/22, Steven Sacks | BLITZ <[EMAIL PROTECTED]>:

Saw this recently in code and was surprised that it worked but it's
pretty cool.

a = "foo";
b = "bar";
c = a || b;
trace(c);
-- foo

a = 0;
// or a = "";
// or a = false;
// or a = null;
// or a is undefined
b = "bar";
c = a || b;
trace(c);
-- bar

It will return b if a is an empty string, false, null, 0 or undefined.

Interesting shortcut.



_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to