René's URL Explorer Experiment


Title: JavaScript String Compare example - Web Code Geeks - 2026

Open Graph Title: JavaScript String Compare example - Web Code Geeks - 2026

Description: Interested to learn more about String compare in JS? Check out our Tutorial where we Compare strings with numbers & do a Case insensitive string comparison!

Open Graph Description: Interested to learn more about String compare in JS? Check out our Tutorial where we Compare strings with numbers & do a Case insensitive string comparison!

Mail addresses
support@webcodegeeks.com

Opengraph URL: https://www.webcodegeeks.com/javascript/javascript-string-compare-example/

X: @webcodegeeks

Generator: WordPress 6.9.4

direct link

Domain: www.webcodegeeks.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@graph":[{"@type":"Article","@id":"https://www.webcodegeeks.com/javascript/javascript-string-compare-example/#article","isPartOf":{"@id":"https://www.webcodegeeks.com/javascript/javascript-string-compare-example/"},"author":{"name":"Era Balliu","@id":"https://www.webcodegeeks.com/#/schema/person/c27ecf40c810e6396ba93ffb829c7b0e"},"headline":"JavaScript String Compare example","datePublished":"2014-11-13T12:15:35+00:00","dateModified":"2018-06-20T14:05:52+00:00","mainEntityOfPage":{"@id":"https://www.webcodegeeks.com/javascript/javascript-string-compare-example/"},"wordCount":593,"commentCount":0,"publisher":{"@id":"https://www.webcodegeeks.com/#organization"},"image":{"@id":"https://www.webcodegeeks.com/javascript/javascript-string-compare-example/#primaryimage"},"thumbnailUrl":"https://www.webcodegeeks.com/wp-content/uploads/2014/10/js-logo.jpg","articleSection":["JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https://www.webcodegeeks.com/javascript/javascript-string-compare-example/#respond"]}]},{"@type":"WebPage","@id":"https://www.webcodegeeks.com/javascript/javascript-string-compare-example/","url":"https://www.webcodegeeks.com/javascript/javascript-string-compare-example/","name":"JavaScript String Compare example - Web Code Geeks - 2026","isPartOf":{"@id":"https://www.webcodegeeks.com/#website"},"primaryImageOfPage":{"@id":"https://www.webcodegeeks.com/javascript/javascript-string-compare-example/#primaryimage"},"image":{"@id":"https://www.webcodegeeks.com/javascript/javascript-string-compare-example/#primaryimage"},"thumbnailUrl":"https://www.webcodegeeks.com/wp-content/uploads/2014/10/js-logo.jpg","datePublished":"2014-11-13T12:15:35+00:00","dateModified":"2018-06-20T14:05:52+00:00","description":"Interested to learn more about String compare in JS? Check out our Tutorial where we Compare strings with numbers & do a Case insensitive string comparison!","breadcrumb":{"@id":"https://www.webcodegeeks.com/javascript/javascript-string-compare-example/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https://www.webcodegeeks.com/javascript/javascript-string-compare-example/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https://www.webcodegeeks.com/javascript/javascript-string-compare-example/#primaryimage","url":"https://www.webcodegeeks.com/wp-content/uploads/2014/10/js-logo.jpg","contentUrl":"https://www.webcodegeeks.com/wp-content/uploads/2014/10/js-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https://www.webcodegeeks.com/javascript/javascript-string-compare-example/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://www.webcodegeeks.com/"},{"@type":"ListItem","position":2,"name":"JavaScript","item":"https://www.webcodegeeks.com/category/javascript/"},{"@type":"ListItem","position":3,"name":"JavaScript String Compare example"}]},{"@type":"WebSite","@id":"https://www.webcodegeeks.com/#website","url":"https://www.webcodegeeks.com/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https://www.webcodegeeks.com/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://www.webcodegeeks.com/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https://www.webcodegeeks.com/#organization","name":"Exelixis Media P.C.","url":"https://www.webcodegeeks.com/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https://www.webcodegeeks.com/#/schema/logo/image/","url":"https://www.webcodegeeks.com/wp-content/uploads/2022/06/exelixis-logo.png","contentUrl":"https://www.webcodegeeks.com/wp-content/uploads/2022/06/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https://www.webcodegeeks.com/#/schema/logo/image/"},"sameAs":["https://www.facebook.com/webcodegeeks","https://x.com/webcodegeeks"]},{"@type":"Person","@id":"https://www.webcodegeeks.com/#/schema/person/c27ecf40c810e6396ba93ffb829c7b0e","name":"Era Balliu","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https://www.webcodegeeks.com/#/schema/person/image/","url":"https://secure.gravatar.com/avatar/f6adddf7eada210f682608fea9d8159441369ec622998a5851a447e0a2bfa3f3?s=96&d=mm&r=g","contentUrl":"https://secure.gravatar.com/avatar/f6adddf7eada210f682608fea9d8159441369ec622998a5851a447e0a2bfa3f3?s=96&d=mm&r=g","caption":"Era Balliu"},"description":"Era is a Telecommunications Engineering student, with a great passion for new technologies. Up until now she has been coding with HTML/CSS, Bootstrap and other front-end coding languages and frameworks, and her recent love is Angular JS.","sameAs":["http://www.webcodegeeks.com/","https://www.facebook.com/era.balliu.7","https://www.instagram.com/eraballiu/","https://www.linkedin.com/in/eraballiu","https://www.pinterest.com/001r2gw0jt0ln6d/","https://x.com/BalliuEra","https://www.youtube.com/c/eraballiu"],"url":"https://www.webcodegeeks.com/author/era-balliu/"}]}
{"@context":"http:\/\/schema.org","@type":"BreadcrumbList","@id":"#Breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"item":{"name":"Home","@id":"https:\/\/www.webcodegeeks.com\/"}},{"@type":"ListItem","position":2,"item":{"name":"JavaScript","@id":"https:\/\/www.webcodegeeks.com\/category\/javascript\/"}}]}
{"@context":"http:\/\/schema.org","@type":"Article","dateCreated":"2014-11-13T14:15:35+02:00","datePublished":"2014-11-13T14:15:35+02:00","dateModified":"2018-06-20T17:05:52+03:00","headline":"JavaScript String Compare example","name":"JavaScript String Compare example","keywords":[],"url":"https:\/\/www.webcodegeeks.com\/javascript\/javascript-string-compare-example\/","description":"A very common operation for most developers is String Compare, be the language they use JavaScript, C\/C++, Java, whatever. To be honest, the programming language doesn't even matter. At some point you","copyrightYear":"2014","articleSection":"JavaScript","articleBody":"A very common operation for most developers is String Compare, be the language they use JavaScript, C\/C++, Java, whatever. To be honest, the programming language doesn't even matter. At some point you will have to compare those strings. In this example we will learn how to do that using JavaScript.\r\n\r\nWe will use:\r\n\r\n \tJavaScript\r\n\r\n\r\nSimple Comparison\r\nWe will start by having you give a look at the following example:\r\n\r\n[js]\r\nvar s = 'string1';\r\n\r\nif(s == 'string1') {\r\n    alert(true);\r\n} else {\r\n    alert(false);\r\n}\r\n[\/js]\r\n\r\nYou will notice that the code puts an alert that says true on the screen. Pretty logical, as the strings are obviously equal.But...\r\nComparing strings with numbers?!\r\nHave a look at the following code snippet:\r\n\r\n[js]\r\nvar s = '16';\r\n\r\nif(s == 16) {\r\n    alert(true);\r\n} else {\r\n    alert(false);\r\n}\r\n[\/js]\r\n\r\nIt shows true. Confused much? Are you asking yourself why did it turn out true when a string can't possibly be equal to a number? I will tell you why after you look at this improved version of the last code:\r\n\r\n[js]\r\nvar s = '16';\r\n\r\nif(s === 16) {\r\n    alert(true);\r\n} else {\r\n    alert(false);\r\n}\r\n[\/js]\r\n\r\nDid you notice the difference? It's in the operator: We were using == and now we're using ===. While the first one only checks if the variables are equal, the second one also considers the variable types, which should be the same too. That's why the improved example will show you the result false. If it still seems strange why would JavaScript consider 123 as equal to '123' then let me tell you JavaScript comparison operator use .toString() operators for types that are not strings.\r\nCase insensitive string comparison\r\nSometimes you want to compare strings that only differ by one being sentence case and the other lowercase or uppercase. But if you are only interested in the content and not the formatting, the comparison way we showed you in the previous paragraphs is not very convenient.\r\n\r\nOne way would be to convert both strings to uppercase and then compare, which would make the code go like this:\r\n\r\n[js]\r\nvar str1 = "Sentence Case";\r\nvar str2 = "sentence case";\r\nvar res1 = str1.toUpperCase();\r\nvar res2 = str2.toUpperCase();\r\n\r\nif(res1 == res2) {\r\n    alert(true);\r\n} else {\r\n    alert(false);\r\n[\/js]\r\n\r\nRemember that casing is a locale specific operation. Depending on the scenario you may want to take that in to account. For example, if you are comparing names of two people you may want to consider locale but if you are comparing machine generated values such as UUID then you might not.\r\n\r\nIt is preferred to normalize your strings to uppercase, though you can even normalize them to lowercase. That's because a small group of characters, when turned to lowercase make a round trip, which means they convert to a different locale, showing character data differently (here you have an example of the problem).\r\n\r\nAlso, please note that in some languages even normalizing characters to uppercase can result in errors, as is the example of Turkish language.\r\n\r\nIn these cases we might further improve the previous code by using the following function:\r\n\r\n[js]\r\nfunction compareStrings (string1, string2, ignoreCase, useLocale) {\r\n    if (ignoreCase) {\r\n        if (useLocale) {\r\n            string1 = string1.toLocaleLowerCase();\r\n            string2 = string2.toLocaleLowerCase();\r\n        }\r\n        else {\r\n            string1 = string1.toLowerCase();\r\n            string2 = string2.toLowerCase();\r\n        }\r\n    }\r\n\r\n    return string1 === string2;\r\n}\r\n[\/js]\r\n\r\nThat is how you compare strings in JavaScript, taking into account the problems you may encounter in doing so.\r\nDownload the source code for JavaScript String Compare Example\r\nThis was an example of string comparison, using JavaScript.\r\nDownload\r\nYou can download the source code for this example here: StringCompareJavascript","publisher":{"@id":"#Publisher","@type":"Organization","name":"Web Code Geeks","logo":{"@type":"ImageObject","url":"\/wp-content\/uploads\/2015\/12\/WebCodeGeeks-logo.png"},"sameAs":["http:\/\/feeds.feedburner.com\/WebCodeGeeks","https:\/\/www.facebook.com\/webcodegeeks","https:\/\/twitter.com\/webcodegeeks","https:\/\/www.youtube.com\/channel\/UCcJkBzpdp8TWzzu0bSjzikw","https:\/\/github.com\/webcodegeeks"]},"sourceOrganization":{"@id":"#Publisher"},"copyrightHolder":{"@id":"#Publisher"},"mainEntityOfPage":{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/javascript\/javascript-string-compare-example\/","breadcrumb":{"@id":"#Breadcrumb"}},"author":{"@type":"Person","name":"Era Balliu","url":"https:\/\/www.webcodegeeks.com\/author\/era-balliu\/"},"image":{"@type":"ImageObject","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg","width":1200,"height":150}}

og:localeen_US
og:typearticle
og:site_nameWeb Code Geeks
article:publisherhttps://www.facebook.com/webcodegeeks
article:authorhttps://www.facebook.com/era.balliu.7
article:published_time2014-11-13T12:15:35+00:00
article:modified_time2018-06-20T14:05:52+00:00
og:imagehttps://www.webcodegeeks.com/wp-content/uploads/2014/10/js-logo.jpg
og:image:width150
og:image:height150
og:image:typeimage/jpeg
authorEra Balliu
twitter:cardsummary_large_image
twitter:creator@BalliuEra
twitter:label1Written by
twitter:data1Era Balliu
twitter:label2Est. reading time
twitter:data23 minutes
NoneIE=edge
msapplication-TileImagehttps://www.webcodegeeks.com/wp-content/uploads/2014/10/WebCodeGeeks-Favicon.png

Links:

Knowledge Basehttps://www.webcodegeeks.com/
Minibookshttps://www.webcodegeeks.com/minibook/
Courseshttps://www.webcodegeeks.com/courses/
Resourceshttps://www.webcodegeeks.com/resources/
Dealshttps://www.webcodegeeks.com/resources/deals/
Join Ushttps://www.webcodegeeks.com/join-us/
WCGhttps://www.webcodegeeks.com/join-us/wcg/
W4Ghttps://www.webcodegeeks.com/join-us/w4g/
Terms & Conditionshttps://www.webcodegeeks.com/join-us/w4g/terms-conditions/
Submission Guidelineshttps://www.webcodegeeks.com/join-us/w4g/submission-guidelines/
Abouthttps://www.webcodegeeks.com/about/
About WCGshttps://www.webcodegeeks.com/about/about-wcgs/
Advertisinghttps://www.webcodegeeks.com/about/advertising/
Terms of Usehttps://www.webcodegeeks.com/about/terms-of-use/
Privacy Policyhttps://www.webcodegeeks.com/about/privacy-policy/
RSShttp://feeds.feedburner.com/WebCodeGeeks
Facebookhttps://www.facebook.com/webcodegeeks
Xhttps://twitter.com/webcodegeeks
YouTubehttps://www.youtube.com/channel/UCcJkBzpdp8TWzzu0bSjzikw
GitHubhttps://github.com/webcodegeeks
Menuhttps://www.webcodegeeks.com/javascript/javascript-string-compare-example/
https://www.webcodegeeks.com/
Search for https://www.webcodegeeks.com/javascript/javascript-string-compare-example/
ASP.NEThttps://www.webcodegeeks.com/category/asp-net/
Cloudhttps://www.webcodegeeks.com/category/cloud/
CSShttps://www.webcodegeeks.com/category/css/
Bootstraphttps://www.webcodegeeks.com/category/css/bootstrap/
DevOpshttps://www.webcodegeeks.com/category/devops/
HTML5https://www.webcodegeeks.com/category/html5/
JavaScripthttps://www.webcodegeeks.com/category/javascript/
Angular.jshttps://www.webcodegeeks.com/category/javascript/angular-js/
Backbone.jshttps://www.webcodegeeks.com/category/javascript/backbone-js/
ClojureScripthttps://www.webcodegeeks.com/category/javascript/clojurescript/
Edge.jshttps://www.webcodegeeks.com/category/javascript/edge-js/
jQueryhttps://www.webcodegeeks.com/category/javascript/jquery/
Node.jshttps://www.webcodegeeks.com/category/javascript/node-js/
Prototypehttps://www.webcodegeeks.com/category/javascript/prototype/
RequireJShttps://www.webcodegeeks.com/category/javascript/requirejs/
React.jshttps://www.webcodegeeks.com/category/javascript/react-js/
NoSQLhttps://www.webcodegeeks.com/category/nosql/
PHPhttps://www.webcodegeeks.com/category/php/
Pythonhttps://www.webcodegeeks.com/category/python/
Rubyhttps://www.webcodegeeks.com/category/ruby/
Web Devhttps://www.webcodegeeks.com/category/web-development/
Web Servershttps://www.webcodegeeks.com/category/web-servers/
WordPresshttps://www.webcodegeeks.com/category/wordpress/
Meta WCGhttps://www.webcodegeeks.com/category/meta-wcg/
Homehttps://www.webcodegeeks.com/
JavaScripthttps://www.webcodegeeks.com/category/javascript/
JavaScripthttps://www.webcodegeeks.com/category/javascript/
https://www.webcodegeeks.com/author/era-balliu/
Era Balliuhttps://www.webcodegeeks.com/author/era-balliu/
Download Nowhttps://www.webcodegeeks.com/javascript/javascript-string-compare-example/
herehttp://en.wikipedia.org/wiki/Capital_%E1%BA%9E
Turkishhttp://www.i18nguy.com/unicode/turkish-i18n.html
StringCompareJavascripthttps://www.webcodegeeks.com/wp-content/uploads/2014/11/StringCompareJavascript.zip
Terms https://www.webcodegeeks.com/about/terms-of-use/
Privacy Policyhttps://www.webcodegeeks.com/about/privacy-policy/
Sign uphttps://www.webcodegeeks.com/javascript/javascript-string-compare-example/
https://www.webcodegeeks.com/author/era-balliu/
Era Balliuhttps://www.webcodegeeks.com/author/era-balliu/
https://www.webcodegeeks.com/author/era-balliu/
Era Balliuhttps://www.webcodegeeks.com/author/era-balliu/
Website https://www.webcodegeeks.com/
Facebook https://www.facebook.com/era.balliu.7
X http://BalliuEra
LinkedIn https://www.linkedin.com/in/eraballiu
YouTube https://www.youtube.com/c/eraballiu
Pinterest https://www.pinterest.com/001r2gw0jt0ln6d/
Instagram https://www.instagram.com/eraballiu/
GitHub https://github.com/balliuera
https://www.webcodegeeks.com/javascript/javascript-table-example/
Javascript Table Examplehttps://www.webcodegeeks.com/javascript/javascript-table-example/
https://www.webcodegeeks.com/javascript/javascript-document-ready-example/
JavaScript Document Ready Examplehttps://www.webcodegeeks.com/javascript/javascript-document-ready-example/
https://www.webcodegeeks.com/javascript/javascript-textbox-example/
Javascript Textbox Examplehttps://www.webcodegeeks.com/javascript/javascript-textbox-example/
https://www.webcodegeeks.com/javascript/javascript-submit-form-example/
JavaScript Submit Form Examplehttps://www.webcodegeeks.com/javascript/javascript-submit-form-example/
https://www.webcodegeeks.com/javascript/javascript-copy-to-clipboard-example/
Javascript copy to clipboard examplehttps://www.webcodegeeks.com/javascript/javascript-copy-to-clipboard-example/
https://www.webcodegeeks.com/javascript/javascript-sort-array-example/
JavaScript Sort Array Examplehttps://www.webcodegeeks.com/javascript/javascript-sort-array-example/
https://www.webcodegeeks.com/javascript/javascript-for-loop-example/
JavaScript For Loop Examplehttps://www.webcodegeeks.com/javascript/javascript-for-loop-example/
https://www.webcodegeeks.com/javascript/javascript-frame-example/
Javascript Frame Examplehttps://www.webcodegeeks.com/javascript/javascript-frame-example/
Termshttps://www.webcodegeeks.com/about/terms-of-use/
Privacy Policyhttps://www.webcodegeeks.com/about/privacy-policy/
Termshttps://www.webcodegeeks.com/about/terms-of-use/
Privacy Policyhttps://www.webcodegeeks.com/about/privacy-policy/
Learn how your comment data is processed.https://akismet.com/privacy/
WCGhttps://www.webcodegeeks.com/join-us/wcg
guest writerhttps://www.webcodegeeks.com/join-us/w4g
Terms https://www.systemcodegeeks.com/about/terms-of-use/
Privacy Policyhttps://www.webcodegeeks.com/about/privacy-policy/
Sign uphttps://www.webcodegeeks.com/javascript/javascript-string-compare-example/
Courseshttps://www.webcodegeeks.com/courses/
Minibookshttps://www.webcodegeeks.com/minibook/
Resourceshttps://www.webcodegeeks.com/resources
.NET Code Geekshttps://www.dotnetcodegeeks.com
Java Code Geekshttps://www.javacodegeeks.com
System Code Geekshttps://www.systemcodegeeks.com/
Web Code Geekshttps://www.webcodegeeks.com
Single Page Appshttps://www.webcodegeeks.com/javascript/angular-js/single-page-apps/
Javascript copy to clipboard examplehttps://www.webcodegeeks.com/javascript/javascript-copy-to-clipboard-example/
JQuery Autocomplete Widget Examplehttps://www.webcodegeeks.com/javascript/jquery/jquery-autocomplete-widget-example/
JavaScript For Loop Examplehttps://www.webcodegeeks.com/javascript/javascript-for-loop-example/
Twitter Bootstrap Modal Examplehttps://www.webcodegeeks.com/web-development/twitter-bootstrap-modal-example/
JavaScript Sort Array Examplehttps://www.webcodegeeks.com/javascript/javascript-sort-array-example/
JavaScript Document Ready Examplehttps://www.webcodegeeks.com/javascript/javascript-document-ready-example/
JavaScript String Compare examplehttps://www.webcodegeeks.com/javascript/javascript-string-compare-example/
HTML5 Drag and Drop Examplehttps://www.webcodegeeks.com/html5/html5-drag-and-drop-example/
JavaScript Submit Form Examplehttps://www.webcodegeeks.com/javascript/javascript-submit-form-example/
Exelixis Media P.C.http://www.exelixismedia.com/
Terms of Usehttps://www.webcodegeeks.com/about/terms-of-use/
Privacy Policyhttps://www.webcodegeeks.com/about/privacy-policy/
RSShttp://feeds.feedburner.com/WebCodeGeeks
Facebookhttps://www.facebook.com/webcodegeeks
Xhttps://twitter.com/webcodegeeks
YouTubehttps://www.youtube.com/channel/UCcJkBzpdp8TWzzu0bSjzikw
GitHubhttps://github.com/webcodegeeks
Facebook https://www.facebook.com/sharer.php?u=https://www.webcodegeeks.com/javascript/javascript-string-compare-example/
X https://x.com/intent/post?text=JavaScript%20String%20Compare%20example&url=https://www.webcodegeeks.com/javascript/javascript-string-compare-example/
WhatsApp https://api.whatsapp.com/send?text=JavaScript%20String%20Compare%20example%20https://www.webcodegeeks.com/javascript/javascript-string-compare-example/
Telegram https://telegram.me/share/url?url=https://www.webcodegeeks.com/javascript/javascript-string-compare-example/&text=JavaScript%20String%20Compare%20example
Back to top button https://www.webcodegeeks.com/javascript/javascript-string-compare-example/#go-to-tie-body
Close https://www.webcodegeeks.com/javascript/javascript-string-compare-example/
RSShttp://feeds.feedburner.com/WebCodeGeeks
Facebookhttps://www.facebook.com/webcodegeeks
Xhttps://twitter.com/webcodegeeks
YouTubehttps://www.youtube.com/channel/UCcJkBzpdp8TWzzu0bSjzikw
GitHubhttps://github.com/webcodegeeks
javascript:void(0)
Close https://www.webcodegeeks.com/javascript/javascript-string-compare-example/

Viewport: width=device-width, initial-scale=1.0

Robots: index, follow, max-image-preview:large, max-snippet:-1, max-video-preview:-1


URLs of crawlers that visited me.