Last active
August 29, 2015 14:10
-
-
Save adamloving/65d4f2cc3dda1e1ce910 to your computer and use it in GitHub Desktop.
javascript string compare.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (1 == '1') console.log('1. 1 == "1"'); | |
if (1 === '1') {} else console.log('2. 1 is not === "1" (types different)'); | |
var a = 'a'; | |
var a1 = a; | |
var a2 = 'a'; | |
if (a == a1) console.log('3. a == a1'); | |
if (a == a2) console.log('4. a == a2'); | |
if (a === a2) console.log('5. even a ==== a2 (equal value and type)'); | |
if ('0' < 'A') console.log('6. "0" is less than "A"'); | |
if ('A' < 'a') console.log('7. "A" is less than "a"'); | |
if ('a' < 'aa') console.log('8. "a" is less than "aa"'); | |
var strings = ['a', 'b', 'A', '!', 'z', 'Z', 'Alpha', 'alpha', '0', '1', '111']; | |
console.log('9. sorted strings', strings.sort()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output is