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>