...

View Full Version : I dont recognize this character in code



PrimeLens
12-31-2010, 05:17 AM
Hi, it's my first post and first thread, actually I joined to ask this question.
I did try searching first but for some reason when I put this character in google search fields
I never find what I want, maybe not being recognized.

here's the code

this.size=a.size||2000;
this.handle_event=a.handle_event||'click';

my question ... what is the || character(s)?

I'm sure this must be laughably simple and thanks in advance
(new to learning js)

Nile
12-31-2010, 05:28 AM
Logical OR. Some rules to remember:
If the first expression evaluates to true, the value of that expression (unchanged) is returned.
If the first expression does NOT evaluate to true (ie: it's null or undefined), then the value of the second expression is evaluated and returned.
false || anything always evaluates to false
true || anything always evaluates to true
http://www.javascriptkit.com/jsref/comparison_operators.shtml

PrimeLens
12-31-2010, 06:14 AM
Funnily enough I knew || meant OR from actionscript days but seeing it in the assignment of a variable threw me! Double pipe what? :)
Thanks Nile.

Nile
12-31-2010, 06:16 AM
No problem

Krupski
12-31-2010, 10:15 PM
Funnily enough I knew || meant OR from actionscript days but seeing it in the assignment of a variable threw me! Double pipe what? :)
Thanks Nile.

Single and double mean different things.

A single "and" or a single "or" are bitwise operators. For example, "1 | 2" is "3" because 0001 or 0010 is 0011.

Another example: "2 & 6" is "2" because 0010 and 1010 is 0010.

Double "and" and "or" are comparison opeartors. For example (pseudo code):



if (enough_money && want_car)
{
purchase_car;
pay_for_car;
}


...wheras....



if (not_enough_money || want_car)
{
purchase_car;
cannot_pay_for_car;
kicked_out_of_dealership;
}



Make sense? :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum