
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
JavaScript Function Definitions
The function definition basically consists of the keyword function and then the name of the function, the function parameters and a set of curly braces enclosing the JavaScript statements.
Following is the code for implementing function definitions in JavaScript −
Example
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .sample { font-size: 18px; font-weight: 500; } </style> </head> <body> <h1>JavaScript Function Definitions</h1> <div class="sample"></div> <button class="Btn">CLICK HERE</button> <h3>Click on the above buttons to see the function definitions</h3> <script> let sampleEle = document.querySelector(".sample"); function helloWorld() { alert("HELLO WORLD"); } let testFunction = function () { alert("TEST FUNCTION"); }; document.querySelector(".Btn").addEventListener("click", () => { sampleEle.innerHTML = helloWorld + "<br>" + testFunction; }); </script> </body> </html>
Output
On clicking the “CLICK HERE” button −
- Related Articles
- Definitions Related to Illumination
- What are the rules to be followed for Object Definitions in JavaScript?
- Mathematical Logical Terms and Definitions
- Computer Storage Definitions and Notations
- Allusion and Illusion: Definitions and Examples
- Narrators in Literature: Types and Definitions
- How to get the details of multiple function definitions in a database from AWS Data catalog using Boto3
- How do we add glossary definitions in HTML?
- What are the definitions of Conduction and Convection?
- Operational and Colloquial definitions of Peace in Psychology
- Function returning another function in JavaScript
- Date.getTime() function JavaScript
- Math.atan() function JavaScript
- Math.min() function JavaScript
- JavaScript Sleep() function?

Advertisements