JavaScript에서 선행 0을 보존할 방법은 없습니다. 그러나 이 id를 문자열로 간주하고 인수로 전달할 수 있습니다.
예시
다음 코드를 실행하여 선행 0을 문자열로 만들어 보존할 수 있습니다. −
<html>
<head>
<script>
function sayHello(name, age, id) {
document.write (name + " is " + age + " years old, with id = "+id);
}
</script>
</head>
<body>
<p>Click the following button to call the function</p>
<form>
<input type="button" onclick="sayHello('John', 26, '0678')"
value="Display Employee Info">
</form>
</body>
</html>