Open In App

How to Call a Function in JavaScript ?

Last Updated : 29 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Calling a function in JavaScript is quite straightforward. You use the function name followed by parentheses ().

Example 1: Here, sayHello is the function, and to call it, you simply write sayHello(). If the function takes parameters, you include them inside the parentheses.

Javascript




function sayHello() {
    console.log("Hello, World!");
}
 
// Calling the function
sayHello();


Output

Hello, World!

Example 2: Here, the function greet takes a name parameter, and when calling it, you provide a value for the parameter like this: greet("Alice").

Javascript




function greet(name) {
    console.log("Hello, " + name + "!");
}
 
// Calling the function with an argument
greet("Alice");


Output

Hello, Alice!

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads