JavaScript에서 음수를 양수로 변환하려면 JavaScript에서 abs() 메서드를 사용하십시오. 이 메서드는 숫자의 절대값을 반환합니다.
예시
다음 코드를 실행하여 음수를 양수로 변환할 수 있습니다 -
<html>
<head>
<title>JavaScript Math abs() Method</title>
</head>
<body>
<script>
var value = Math.abs(-1);
document.write("First Test Value : " + value );
var value = Math.abs(null);
document.write("<br />Second Test Value : " + value );
var value = Math.abs(20);
document.write("<br />Third Test Value : " + value );
var value = Math.abs("string");
document.write("<br />Fourth Test Value : " + value );
</script>
</body>
</html>