PDA

View Full Version : :: what does this mean? ::


babelfish
10-09-2002, 05:06 PM
var noPackage=!parent.CDTreeNav.document.cdtreebuild.cat1.selectedIndex;

saw this on a recent script - i dont get the =! i know != is not equal too but what does =! mean? its not the same as not equal cos i tried to swap it round :)

maybe im just being a tool tho :)

beetle
10-09-2002, 05:27 PM
The ! isn't part of the = operator, but is separate and tells JS to get the opposite or NOT from the following statement. When applied to the selectedIndex property of a SELECT element this statement will return true only if the first option is selected, and false for all the rest.

Reads easier this way...var noPackage = !(parent.CDTreeNav.document.cdtreebuild.cat1.selectedIndex);But is the same thing as what you posted. Also, this line gets the same result, and is probably more commonvar noPackage = (parent.CDTreeNav.document.cdtreebuild.cat1[0].selected);So, it seems the coder of this script wants to populate the 'noPackage' variable with a true value if that SELECT element is selected at it's 0 index.

Happy coding! :D

brothercake
10-09-2002, 05:42 PM
It's very useful that syntax - for eg - if one or the other, or neither, of two conditions can be true, but not both be true, then

if (!(cond1&&cond2))

beetle
10-09-2002, 06:41 PM
Originally posted by brothercake
It's very useful that syntax - for eg - if one or the other, or neither, of two conditions can be true, but not both be true, then

if (!(cond1&&cond2)) Can't you just use XOR for that?

if (cond1 ^ cond2)

boywonder
10-10-2002, 12:15 AM
When neither condition is true xor wouldn't work as brother cake intended...

(false^false) //false

(!(false&&false)) //true

joh6nn
10-10-2002, 01:39 AM
as far as i know, Xor in javascript, applies only to integers. i've never seen it used period, but my documentation ( the Guide ) only lists it as being used as a bitwise operator, for integers.

beetle
10-10-2002, 01:51 AM
boywonder

*nod

joh6nn

XOR when performed on either of the primitive data types or booleans will return a 1 or 0, which as you know will evaluate to true or false within a conditional.

At least, this is true per the results of my experience...