JS Switch Statement
In a case of multiple IF/Else/Else If statements, the switch statement can be used to clean the code up a bit.
The switch statement takes a value, then evaluates the value. If a match is found, it executes the condition.
%MINIFYHTML7ae4f38383df0118fc6e01f23d054bad23%switch(codeOut){
case ERROR:
console.log('Error occurred")
break
case WARN:
console.log('Warning issued')
break
case DEBUG:
console.log('Debug mode')
break
Code language: PHP (php)
If the value for codeOut matches ERROR, then it throws the console log output “Error occurred.” Likewise, if the value is the string WARN it would output ‘Warning issued,” and so on.