Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #26201

Unexpected value when using "<"

Newsgroups comp.lang.javascript
Date 2014-11-23 17:45 -0800
Message-ID <723cd8aa-caff-4530-9977-9884cddeb3c7@googlegroups.com> (permalink)
Subject Unexpected value when using "<"
From RobG <rgqld@iinet.net.au>

Show all headers | View raw


Given the comparison:

  'foo' < 2
  
I was expectingt the result to be *undefined*, based on the abstract relational comparison algorithm[1].

In step 3a, the left hand side is converted to a number using ToNumber('foo'), which returns NaN. Step 3c of the algorithm says:

  If nx is NaN, return undefined

So I was expecting the result to be *undefined*. The introduction to the section also says that the comparison:

    "...produces true, false, or undefined (which indicates that at least one operand is NaN)".
  
However, in the couple of browsers I tested, the result was Boolean false. Can someone please explain, or point to a suitable explanation elsewhere, why the result is *false* and not *undefined*?


1. http://ecma-international.org/ecma-262/5.1/#sec-11.8.5


-- 
RobG

Back to comp.lang.javascript | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Unexpected value when using "<" RobG <rgqld@iinet.net.au> - 2014-11-23 17:45 -0800
  Re: Unexpected value when using "<" Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-24 03:37 +0100
    Re: Unexpected value when using "<" RobG <rgqld@iinet.net.au> - 2014-11-23 19:53 -0800
      Re: Unexpected value when using "<" Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-24 19:43 +0100

csiph-web