16079

Why does “10” > “9” = false? [duplicate]

Question:

This question already has an answer here:

<ul><li> <a href="/questions/7087811/why-is-one-string-greater-than-the-other-when-comparing-strings-in-javascript" dir="ltr" rel="nofollow">Why is one string greater than the other when comparing strings in JavaScript?</a> <span class="question-originals-answer-count"> 3 answers </span> </li> <li> <a href="/questions/5630123/javascript-string-integer-comparisons" dir="ltr" rel="nofollow">Javascript string/integer comparisons</a> <span class="question-originals-answer-count"> 6 answers </span> </li> </ul>

Is this a failure in JavaScript's attempt to convert them to numbers? If so, what numbers are they being converted to? Or what is the logic behind the string 10 being less than the string 9?

Answer1:

It's comparing the strings "alphabetically", and 1 comes before 9 in the character "alphabet".

Recommend

  • Filter Unit from List
  • Difference in performance between calling .localeCompare on string objects and constructing a purpos
  • How to compare same PropertyInfo with different ReflectedType values?
  • Why does updating a hash set to a variable update that variable?
  • Delphi XE3, ugly StringGrid's borders
  • Compare variables PHP
  • SharePoint Designer 2010 - Determine if today's date is within x days of a start date column us
  • rails - convert DateTime to UTC before saving to server
  • several dataProvider per one Test in TestNG
  • how to set variables in a php include file?
  • How to specify input and output paths from cmd.exe for a PowerShell script?
  • How to make jdk.nashorn.api.scripting.JSObject visible in plugin [duplicate]
  • Z3: Convert between FP and BitVector?
  • How does document.ready work with angular element directives?
  • What does 'Language neutral' mean with regard to MAKELANGID?
  • Zurb Foundation _global.scss meta styles for js?
  • jQuery ready not fired after rails link_to is clicked
  • Date Conversion from yyyy-mm-dd to dd-mm-yyyy
  • How to define and use opencv mat of user type
  • Content-Length header not returned from Pylons response
  • Extracting HTML between tags
  • Ajax Loaded meta Tags
  • Xamarin Forms - UWP Fonts
  • Counter field in MS Access, how to generate?
  • HTML download movie download link
  • Updating server-side rendering client-side
  • vba code to select only visible cells in specific column except heading
  • Arrow is showed instead of the material design version hamburger icon. Why doesn't syncState in
  • When should I choose bucket sort over other sorting algorithms?
  • Convert array of 8 bytes to signed long in C++
  • Jquery - Jquery Wysiwyg return html as a string
  • AT Commands to Send SMS not working in Windows 8.1
  • Arrays break string types in Julia
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • WPF Applying a trigger on binding failure
  • How to set the response of a form post action to a iframe source?
  • Java static initializers and reflection
  • Setting background image for body element in xhtml (for different monitors and resolutions)
  • apache spark aggregate function using min value
  • Sorting a 2D array using the second column C++