Click to See Complete Forum and Search --> : The double ampersands in methods


metal5
07-25-2004, 03:17 AM
I'm reading on javascript building. What does the double ampersands mean in methods?

For example:

if(navigator.plugins && navigator.plugins.length>0) {

document.write("You have the following plugins:.....

I read that both values on each side of the double ampersands have to be true for the code to work, but is this true---
navigator.plugins && navigator.plugins.length? I wouldn't think so. In order for this to be 'true' wouldn't the it have to be navigator.plugins && navigator.plugins. The book I'm reading is an excellent book but I'm stumped on how it barely explains the purpose of the double ampersand.

Any suggestions appreciated.

metal5:eek: :eek:

spufi
07-25-2004, 05:45 AM
Originally posted by metal5
if(navigator.plugins && navigator.plugins.length>0)

If navigator.plugins are true/exist and if navigator.plugins.length is greater than 0, then do the following.

buntine
07-25-2004, 12:50 PM
All valid expressions in an If statement will return a boolean (true/false) value. Thus, if the array navigator.plugins contains more than zero items, the expression will return true.

The double ampersand conditional operator tells the runtime environment that it does not have to evaluate the second operand if the first one returned true.

If you were to use a single ampersand binary operator, then both operands would be evaluated with no exception.

The same concept applies for the OR operators (||, |).

Regards.

metal5
07-25-2004, 04:20 PM
Thank you to everyone who replied;

Its not so confusing now. I just never saw the double ampersand. Now I can get on with reading the rest of the javascript book.

metal5

buntine
07-25-2004, 05:22 PM
Your welcome.

Remembering all of the little things about operators can be difficult!

ray326
07-25-2004, 11:36 PM
Originally posted by buntine

If you were to use a single ampersand binary operator, then both operands would be evaluated with no exception.

The same concept applies for the OR operators (||, |).

And the result of & and | is not a boolean.