Skip to content

Instantly share code, notes, and snippets.

@xxl007
Created April 20, 2014 17:48
Show Gist options
  • Save xxl007/11120334 to your computer and use it in GitHub Desktop.
Save xxl007/11120334 to your computer and use it in GitHub Desktop.
Conditionally Comparing Strings
// 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