JavaScript에서 대소문자를 구분하지 않는 switch-case를 사용하려면 입력을 모두 대문자 또는 모두 소문자로 만드십시오.
예시
다음 코드를 실행하여 대소문자를 구분하지 않는 스위치를 사용하는 방법을 배울 수 있습니다.
<!DOCTYPE html>
<html>
<body>
<h3>JavaScript Strings</h3>
<p id="test"></p>
<script>
var str = "amit";
str = str.toUpperCase();
switch (str) {
case 'AMIT': document.write("The name is AMIT <br>");
break;
case 'JOHN': document.write("The name is JOHN <br>");
break;
default: document.write("Unknown name<br>")
}
document.write("Exiting switch block");
</script>
</body>
</html>