STRANGE 🙄 COMPARISON IN JAVASCRIPT
Let’s stop here for a moment! Can you guess the output? “6.1” < “11.5” ... was your answer a true? or a false?
If it was a true?, then Whaaatt!?? Let us understand how it works! Y O U A R E W R O N G!
String Comparison in Javascript Based on The Abstract Relational Comparison Algorithm in ES5, Javascript process the string comparison in the following way. '6.1' < '11.5' '6' -> 54 '1' -> 49 It keeps moving on to the next characters of the both strings sequentially till the end of string, comparing the unicode value of the each characters. 54 < 49 It then exits after comparing different unicode value. In our case, as the unicode value of the first character from the first string is greater, the first string is greater. Hence the output is FALSE.
'Wow' < 'Woww' 'Woz' < 'Wow' Let’s see if you really understood the concept. What’s the output for the below snippets? Shoot out your answers in the comments below! 👇

String comparison in javascript

  • 1.
  • 2.
    Let’s stop herefor a moment! Can you guess the output? “6.1” < “11.5” ... was your answer a true? or a false?
  • 3.
    If it wasa true?, then Whaaatt!?? Let us understand how it works! Y O U A R E W R O N G!
  • 4.
    String Comparison inJavascript Based on The Abstract Relational Comparison Algorithm in ES5, Javascript process the string comparison in the following way. '6.1' < '11.5' '6' -> 54 '1' -> 49 It keeps moving on to the next characters of the both strings sequentially till the end of string, comparing the unicode value of the each characters. 54 < 49 It then exits after comparing different unicode value. In our case, as the unicode value of the first character from the first string is greater, the first string is greater. Hence the output is FALSE.
  • 5.
    'Wow' < 'Woww' 'Woz'< 'Wow' Let’s see if you really understood the concept. What’s the output for the below snippets? Shoot out your answers in the comments below! 👇