Last active
September 26, 2018 06:46
-
-
Save Psvensso/cd6259af44ca3b93b9b27351e0cef523 to your computer and use it in GitHub Desktop.
Switch is not an If-Else - JavaScript
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
function _t(){ | |
var result = "null"; | |
switch ("A") { | |
case "A": { | |
result += "A"; | |
} | |
case "B": { | |
result += "B"; | |
} | |
case "C": { | |
result += "C"; | |
break; | |
} | |
default: | |
result += "default"; | |
} | |
return result; | |
} | |
//Guess what result is | |
console.log("Result was: " + _t()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment