Created
April 20, 2014 17:48
-
-
Save xxl007/11120334 to your computer and use it in GitHub Desktop.
Conditionally Comparing Strings
This file contains hidden or 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
// Use the equality operator (==) within a conditional test: | |
var strName = prompt("What's your name?", ""); | |
if (strName.toUpperCase () == "SHELLEY") { // case sensitive operator! | |
alert("Your name is Shelley! Good for you!"); | |
}else{ | |
alert("Your name isn't Shelley. Bummer."); | |
} | |
// the (==) operator does automatic type conversion while the strict equality operator (===) doesn't. | |
// stringObject == stringLiteral with same string value will yield true while | |
// stringObject === stringLiteral will yield false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment