Why returns false without comparison?

Alper Ceviz
console.log([1,2,3] > null); // returns false

// "1,2,3" > null
// NaN > null
// false => Direct returns false ??

The code returns false. Normally NaN > null must be numeric comparison. But result returned false. Why?

T.J. Crowder

Following the steps in the Abstract Relational Comparison algorithm:

  • [1,2,3] > null - Step 1 (a,b): Apply ToPrimitive to both sides
  • "1,2,3" > null - Step 4 (d, e): Apply ToNumeric to both sides

Now we have NaN > 0, which is false, because any time NaN is involved in any relational operation, the result is false.

In a comment on the question you asked:

But why returns false without comparison.

> is a comparison. I think you mean "without a branching operation or expression" (like if or the conditional operator, ? :). If so, it's because expressions (including relational expressions) have result values whether or not you use those results for branching. The result of a > expression is true or false. If you use that in an if, that's fine, but you don't have to:

const a = 1 > 2;
console.log(a); // false

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why does a comparison of identical dict values in python 3.5.2 returns False?

Why after defining a toString function a comparison between objects returns false?

Why pandas.eval() string comparison returns False

On gremlin console, why predicate 'eq' returning false inside 'is' while direct comparison returns true?

JSTL string comparison always returns false

const char* if() comparison with "SRAD" returns false

Same password values comparison returns false cakephp

Moment.js comparison always returns false

String comparison from nested for returns always false

Beginner Prolog question - comparison always returns false

Part of string comparison always inexplicably returns False

Strange value comparison issue in Kotlin, "===" returns true but "==" returns false

Why toggle checkbox returns false?

Why isUniquelyReferencedNonObjC returns false in this case?

Why `("" || "word") == true` returns false?

Why 'a like a' returns false in MySQL

why get text returns false?

Explanation as to why this String comparison results in false?

Why is comparison to True/False using the "is" operator bad?

Why does this java string comparison prints false?

jscience Real comparison returns false even though values are equal

C++ - Comparison between negative and positive number returns false

Comparison between concatenated String and whole String returns false;

C++ String comparison with same size and content returns false

Base64 comparison using matches() returns false

Why Nothing == (pure Nothing) returns False in Haskell?

Why does `$(document) === $(document)` returns false in jQuery?

Why does Predicates.instanceOf returns false?

Why is the condition in this callback always returns false?

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    pump.io port in URL

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    flutter: dropdown item programmatically unselect problem

  14. 14

    How to use merge windows unallocated space into Ubuntu using GParted?

  15. 15

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  16. 16

    Nuget add packages gives access denied errors

  17. 17

    Svchost high CPU from Microsoft.BingWeather app errors

  18. 18

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  19. 19

    12.04.3--- Dconf Editor won't show com>canonical>unity option

  20. 20

    Any way to remove trailing whitespace *FOR EDITED* lines in Eclipse [for Java]?

  21. 21

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

HotTag

Archive