SlideShare a Scribd company logo
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!
👇

More Related Content

More from Ideas2IT Technologies (20)

PDF
Currying in JavaScript
Ideas2IT Technologies
 
PDF
JS Testing Frameworks
Ideas2IT Technologies
 
PDF
Cool usage of Encoding and Decoding a URI in Javascript
Ideas2IT Technologies
 
PDF
Iterables and Iterators in JavaScript
Ideas2IT Technologies
 
PDF
JavaScript symbols
Ideas2IT Technologies
 
PDF
Json.parse() in JavaScript
Ideas2IT Technologies
 
PDF
Bubble sort in Java Script
Ideas2IT Technologies
 
PDF
Performance analysis in merging arrays - JavaScript
Ideas2IT Technologies
 
PDF
Nullish coalescing in JavaScript
Ideas2IT Technologies
 
PDF
Conditionally add keys in JavaScript
Ideas2IT Technologies
 
PDF
What is Big O in JavaScript - Part-1
Ideas2IT Technologies
 
PDF
Variable hoisting in JavaScript
Ideas2IT Technologies
 
PDF
Formidable ES6 spread operator in JavaScript
Ideas2IT Technologies
 
PDF
Logging in JavaScript - Part-5
Ideas2IT Technologies
 
PDF
Logging in JavaScript - Part-4
Ideas2IT Technologies
 
PDF
Logging in JavaScript - Part-3
Ideas2IT Technologies
 
PDF
Logging in JavaScript - part-2
Ideas2IT Technologies
 
PDF
Logging in JavaScript - part-1
Ideas2IT Technologies
 
PDF
Array vs set in JavaScript
Ideas2IT Technologies
 
PDF
Arguments Object in JavaScript
Ideas2IT Technologies
 
Currying in JavaScript
Ideas2IT Technologies
 
JS Testing Frameworks
Ideas2IT Technologies
 
Cool usage of Encoding and Decoding a URI in Javascript
Ideas2IT Technologies
 
Iterables and Iterators in JavaScript
Ideas2IT Technologies
 
JavaScript symbols
Ideas2IT Technologies
 
Json.parse() in JavaScript
Ideas2IT Technologies
 
Bubble sort in Java Script
Ideas2IT Technologies
 
Performance analysis in merging arrays - JavaScript
Ideas2IT Technologies
 
Nullish coalescing in JavaScript
Ideas2IT Technologies
 
Conditionally add keys in JavaScript
Ideas2IT Technologies
 
What is Big O in JavaScript - Part-1
Ideas2IT Technologies
 
Variable hoisting in JavaScript
Ideas2IT Technologies
 
Formidable ES6 spread operator in JavaScript
Ideas2IT Technologies
 
Logging in JavaScript - Part-5
Ideas2IT Technologies
 
Logging in JavaScript - Part-4
Ideas2IT Technologies
 
Logging in JavaScript - Part-3
Ideas2IT Technologies
 
Logging in JavaScript - part-2
Ideas2IT Technologies
 
Logging in JavaScript - part-1
Ideas2IT Technologies
 
Array vs set in JavaScript
Ideas2IT Technologies
 
Arguments Object in JavaScript
Ideas2IT Technologies
 

Recently uploaded (20)

PDF
Transparency into Your Software’s True Reach
team-WIBU
 
PPTX
Mistakes to Avoid When Selecting Policy Management Software
Insurance Tech Services
 
PDF
Code Once; Run Everywhere - A Beginner’s Journey with React Native
Hasitha Walpola
 
PDF
>Nitro Pro Crack 14.36.1.0 + Keygen Free Download [Latest]
utfefguu
 
PDF
WholeClear Split vCard Software for Split large vCard file
markwillsonmw004
 
PDF
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
PPTX
For my supp to finally picking supp that work
necas19388
 
PDF
IObit Uninstaller Pro 14.3.1.8 Crack for Windows Latest
utfefguu
 
PPTX
computer forensics encase emager app exp6 1.pptx
ssuser343e92
 
PPTX
Quality on Autopilot: Scaling Testing in Uyuni
Oscar Barrios Torrero
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 41
utfefguu
 
PDF
2025年 Linux 核心專題: 探討 sched_ext 及機器學習.pdf
Eric Chou
 
PDF
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
PDF
Rewards and Recognition (2).pdf
ethan Talor
 
PDF
Power BI vs Tableau vs Looker - Which BI Tool is Right for You?
MagnusMinds IT Solution LLP
 
PDF
>Wondershare Filmora Crack Free Download 2025
utfefguu
 
PPTX
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
PDF
From Chaos to Clarity: Mastering Analytics Governance in the Modern Enterprise
Wiiisdom
 
PPTX
Iobit Driver Booster Pro 12 Crack Free Download
chaudhryakashoo065
 
PPTX
CONCEPT OF PROGRAMMING in language .pptx
tamim41
 
Transparency into Your Software’s True Reach
team-WIBU
 
Mistakes to Avoid When Selecting Policy Management Software
Insurance Tech Services
 
Code Once; Run Everywhere - A Beginner’s Journey with React Native
Hasitha Walpola
 
>Nitro Pro Crack 14.36.1.0 + Keygen Free Download [Latest]
utfefguu
 
WholeClear Split vCard Software for Split large vCard file
markwillsonmw004
 
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
For my supp to finally picking supp that work
necas19388
 
IObit Uninstaller Pro 14.3.1.8 Crack for Windows Latest
utfefguu
 
computer forensics encase emager app exp6 1.pptx
ssuser343e92
 
Quality on Autopilot: Scaling Testing in Uyuni
Oscar Barrios Torrero
 
IDM Crack with Internet Download Manager 6.42 Build 41
utfefguu
 
2025年 Linux 核心專題: 探討 sched_ext 及機器學習.pdf
Eric Chou
 
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
Rewards and Recognition (2).pdf
ethan Talor
 
Power BI vs Tableau vs Looker - Which BI Tool is Right for You?
MagnusMinds IT Solution LLP
 
>Wondershare Filmora Crack Free Download 2025
utfefguu
 
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
From Chaos to Clarity: Mastering Analytics Governance in the Modern Enterprise
Wiiisdom
 
Iobit Driver Booster Pro 12 Crack Free Download
chaudhryakashoo065
 
CONCEPT OF PROGRAMMING in language .pptx
tamim41
 
Ad

String comparison in javascript

  • 2. Let’s stop here for a moment! Can you guess the output? “6.1” < “11.5” ... was your answer a true? or a false?
  • 3. If it was a true?, then Whaaatt!?? Let us understand how it works! Y O U A R E W R O N G!
  • 4. 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.
  • 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! 👇