You define a function by using the function
keyword followed by a name that describes the use of the function, a list of zero or more arguments in ()
, and a block of one or more code statements in {}
. For example, the following is a function definition that writes "Hello World"
to the console:
function myFunction(){
console.log("Hello World");
}
To execute the code in myFunction()
, all you need to do is add the following line to the main JavaScript or inside another function:
myFunction();