기본 매개변수는 함수 매개변수를 쉽게 처리하기 위해 사용되었습니다. 기본 매개변수를 쉽게 설정하여 형식 매개변수를 기본값으로 초기화할 수 있습니다. 값이 없거나 정의되지 않은 경우에만 가능합니다.
예시
예를 들어 봅시다 -
<html>
<body>
<script>
// default is set to 1
function inc(val1, inc = 1) {
return val1 + inc;
}
document.write(inc(10,10));
document.write("<br>");
document.write(inc(10));
</script>
</body>
</html>