자바스크립트에서 숫자 를 변환하지 마십시오. 객체 로 숫자는 개체 와 비교할 수 없기 때문에 심지어 개체 개체와 비교할 수 없습니다. .
예시
다음 예에서 제공된 숫자 20은 변수 'x'와 변수 'y' 모두에 할당됩니다. 두 변수를 서로 비교할 때 부울 값 "참 "가 출력과 같이 표시됩니다.
<html>
<body>
<script>
var x = 500;
var y = (500);
document.write((x===y));
document.write("</br>");
document.write(typeof(x));
document.write("</br>");
document.write(typeof(y));
</script>
</body>
</html> 출력
true number number
예시
다음 예에서 변수 "y"는 숫자 에서 바뀝니다. 개체 에 그런 다음 변수 "x"와 비교할 때 부울 값 거짓 출력과 같이 표시됩니다.
<html>
<body>
<script>
var x = 500;
var y = new Number(500);
document.write((x===y));
document.write("</br>");
document.write(typeof(x));
document.write("</br>");
document.write(typeof(y));
</script>
</body>
</html> 출력
false number object