JavaScript를 사용하면 자체 기능도 작성할 수 있습니다. 나중에 스크립트 어딘가에서 함수를 호출하려면 해당 함수의 이름을 쓰기만 하면 됩니다.
예
다음 코드를 실행하여 JavaScript에서 함수를 호출하는 방법을 배울 수 있습니다. −
<html>
<head>
<script>
function sayHello() {
document.write ("Hello there!");
}
</script>
</head>
<body>
<p>Click the following button to call the function</p>
<form>
<input type = "button" onclick = "sayHello()" value = "Say Hello">
</form>
<p>Use different text in write method and then try...</p>
</body>
</html>