What is a function?
A function is a group of code that can be called later. A function is program designed to perform a task and can be later called anywhere in the code. Let's take for instance, you wrote a code to perform a task and you need the same code later, all you need is to call the function of the initial code instead of rewriting the same code over and over.
Function reduce stress of writing code over and over but instead makes it possible to access the code within it by just calling it.So to work with a function in your code , you need to:
-
Define the function
- Call the function
Function Definition
I said earlier that a function can be called anywhere in the code but before you call a function, you need to define the function.
To define a function, you use the 'function' keyword followed by the function name.
SYNTAX
function functionName( ) {
//Statement;
}
Example
//Define a function
function welMessage( ){
alert("Welcome to Zhullyblog");
}
Screenshot
Comments
Post a Comment