Created
February 13, 2013 22:50
-
-
Save say2joe/4949108 to your computer and use it in GitHub Desktop.
Use regular expressions in switch statements.
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
switch (true) { | |
case (/Chrome/).test(navigator.userAgent): | |
console.log("You're using Chrome."); | |
break; | |
case (/MSIE/).test(navigator.userAgent): | |
console.log("Unfortunately, you're using Internet Explorer"); | |
break; | |
default: | |
console.log("You're using a different kinda browser."); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment