Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #26914
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: puzzled by example code using the logical OR |
| Date | 2015-02-23 22:10 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <mcg8ga$gs7$1@dont-email.me> (permalink) |
| References | <088f6cf2-dbfe-4633-8c69-0bed2328a067@googlegroups.com> <XnsA44ADF74E9D86eejj99@194.109.133.133> <87sidwi93w.fsf@bsb.me.uk> |
On Mon, 23 Feb 2015 21:57:55 +0000, Ben Bacarisse wrote:
> "Evertjan." <exxjxw.hannivoort@inter.nl.net> writes:
>
>> JeffG <jeffgutsell@fuse.net> wrote on 23 feb 2015 in
>> comp.lang.javascript:
>>
>>> I've been looking at a discussion of creating objects that
>> are
>>> containers of all related functions and vars. An example
>> first step is
>>> as follows: ar AppSpace = AppSpace || {};
>>> I don't see the purpose of "||". I would appreciate an
>> explanation since
>>> I cannot get a response from the author. I thought the
>> logical OR only
>>> returns true or false based on comparing two values or
>> expressions.
>>
>> Incorrect. That only happens if || compares boolean values.
>>
>> 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 ||, 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].
[1] sometimes referred to as truthy
[2] sometimes referred to as falsey
--
Denis McMahon, denismfmcmahon@gmail.com
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