Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #26916
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: puzzled by example code using the logical OR |
| Date | 2015-02-23 23:39 +0100 |
| Organization | PointedEars Software (PES) |
| Message-ID | <1584643.PrhRbllIxL@PointedEars.de> (permalink) |
| References | <088f6cf2-dbfe-4633-8c69-0bed2328a067@googlegroups.com> <XnsA44ADF74E9D86eejj99@194.109.133.133> <87sidwi93w.fsf@bsb.me.uk> <mcg8ga$gs7$1@dont-email.me> |
Denis McMahon wrote:
> On Mon, 23 Feb 2015 21:57:55 +0000, Ben Bacarisse wrote:
>> "Evertjan." <exxjxw.hannivoort@inter.nl.net> writes:
>>> AppSpace = AppSpace || {};
>>>
>>> AppSpace is set to AppSpace [so effectivly remains so], unless AppSpace
>>> returns false or empty or 0 or undefined, then AppSpace is set to {},
>>> an empty object.
>>
>> It's false, the empty string, 0 (both +0 and -0), NaNs, undefined and
>> null that are considered false. (It's common not to care about -0 and
>> NaNs, but null matters a bit more.)
>
> More generally, when comparing multiple (2 or more) values with ||,
Again, “||” is _not_ a comparison operator; it is a *binary* *logical*
operator (that takes exactly *2* operands, hence “binary”). “x || y || z”
is equivalent to “(x || y) || z”, “a || b || c || d” is equivalent to
“((a || b) || c) || d”, and so forth:
| LogicalORExpression :
| LogicalANDExpression
| LogicalORExpression || LogicalANDExpression
> from left to right, the first "not considered false"[1] value is returned,
> or false if all the values being compared are "considered false"[2].
No; it follows from the grammar and the algorithm: if all operands up to the
second-last one in a chain of “||” operations (see above) yield results that
are converted (by an implementation of the ToBoolean algorithm) to “false”,
then the result of the expression is the result of evaluating the last
operand:
var answer = 0 || +"y" || false || 42;
var zero = void 0 || +"z" || false || 0;
Once again: If you are not certain, do not post. *Nobody* is being helped
by such half-wit guesses and terminology. Read the pertinent Specification,
in this case <http://ecma-international.org/ecma-262/5.1/#sec-11.11>, and
run some *proper* tests based on that before you post. TIA.
--
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not cc me. / Bitte keine Kopien per E-Mail
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
puzzled by example code using the logical OR JeffG <jeffgutsell@fuse.net> - 2015-02-23 11:20 -0800
Re: puzzled by example code using the logical OR "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-02-23 21:57 +0100
Re: puzzled by example code using the logical OR Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-02-23 21:57 +0000
Re: puzzled by example code using the logical OR Denis McMahon <denismfmcmahon@gmail.com> - 2015-02-23 22:10 +0000
Re: puzzled by example code using the logical OR Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-02-23 23:39 +0100
Re: puzzled by example code using the logical OR Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-02-23 23:12 +0100
Re: puzzled by example code using the logical OR Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2015-02-23 23:09 -0300
Re: puzzled by example code using the logical OR Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2015-02-23 23:26 -0300
csiph-web