Here are examples of each:
- Using an expression:
javascriptconst greet = function() {
console.log('Hello, world!');
};
greet(); // calling the function using an expression
In this example, we defined a function expression named greet
. We then called the function by using the function name followed by parentheses ()
.
- Using the function name:
javascriptfunction greet() {
console.log('Hello, world!');
}
greet(); // calling the function using the function name
In this example, we defined a function named greet
. We then called the function by using the function name followed by parentheses ()
.
- Using an arrow function:
javascriptconst greet = () => {
console.log('Hello, world!');
};
greet(); // calling the function using an arrow function
In this example, we defined an arrow function named greet
. We then called the function by using the function name followed by parentheses ()
.
Note that all three methods of calling a function require that the function be defined first. Once the function is defined, you can call it using any of the above methods.