오류 이름 값은 오류 이름을 설정하거나 반환하는 데 사용됩니다. 오류 이름은 아래 값을 반환할 수 있습니다.
| Sl.No | 오류 이름 및 설명 |
|---|---|
| 1 | 평가 오류 eval() 함수의 오류를 나타냅니다. |
| 2 | 범위 오류 숫자 값이 범위를 벗어날 때 발생합니다. |
| 3 | 참조 오류 불법 참조가 발생했을 때 발생 |
| 4 | 구문 오류 구문 오류를 나타냅니다. |
| 5 | 유형 오류 유형 오류를 나타냅니다. |
| 6 | URI 오류 이는 encodeURI()의 오류를 나타냅니다. |
예시
다음은 JavaScript의 오류 이름 값에 대한 코드입니다 -
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
body {
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}
.result {
font-size: 20px;
font-weight: 500;
}
</style>
</head>
<body>
<h1>Error name values in Javascript</h1>
<div style="color: green;" class="result"></div>
<button class="Btn">CLICK HERE</button>
<h3>
Click on the above button to call a variable before it is defined
</h3>
<script>
let resEle = document.querySelector(".result");
document.querySelector(".Btn").addEventListener("click", () => {
try {
resEle.innerHTML = a;
}
catch (err) {
resEle.innerHTML = "Error name = " + err.name;
}
let a = 44;
});
</script>
</body>
</html> 출력
위의 코드는 다음과 같은 출력을 생성합니다 -

'여기를 클릭' 버튼을 클릭하면 -
