Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!weretis.net!feeder4.news.weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: puzzled by example code using the logical OR Date: Mon, 23 Feb 2015 23:39:52 +0100 Organization: PointedEars Software (PES) Lines: 47 Message-ID: <1584643.PrhRbllIxL@PointedEars.de> References: <088f6cf2-dbfe-4633-8c69-0bed2328a067@googlegroups.com> <87sidwi93w.fsf@bsb.me.uk> Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1424731273 19766 eJwFwYEBwDAEBMCVEF46ziP2H6F3caDodAQ8NrbL4K+UBbkhoNEmpntXUi8zWcIznHkfs38t7BI1 (23 Feb 2015 22:41:13 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Mon, 23 Feb 2015 22:41:13 +0000 (UTC) User-Agent: KNode/4.14.2 X-User-ID: eJwFwQkBwDAIA0BLUBIoclYe/xJ2R3P1CjgdXK7EqxRQx7O9oPIEAcuwldNNzSEkL75BRp2h+b7Lexop/AEnJxQk Cancel-Lock: sha1:xfNal8h+valKBSUL9+lSvIohaRo= X-NNTP-Posting-Host: eJwFwQkBwDAIA0BLlJEE5PQB/xJ2h4+LV0EwMJhdWO1Hbayy/eAZRYz3i4CamrxMV56sMf0OuRBv Xref: csiph.com comp.lang.javascript:26916 Denis McMahon wrote: > On Mon, 23 Feb 2015 21:57:55 +0000, Ben Bacarisse wrote: >> "Evertjan." 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 , and run some *proper* tests based on that before you post. TIA. -- PointedEars FAQ: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not cc me. / Bitte keine Kopien per E-Mail