How to Create a Basic JavaScript Function with Parameters?

Estimated read time 1 min read

A JavaScript function can be created by using the “function” keyword, followed by the name of the function, and a list of parameters enclosed in parentheses. The code to be executed when the function is called should be placed inside curly braces. Here’s an example of how to create a basic JavaScript function with parameters:

function greetUser(name, age) {
  console.log("Hello " + name + ", your age is " + age);

In this example, the function is named “greetUser” and it takes two parameters, “name” and “age”. When the function is called, it will log a greeting message to the console that includes the values of the “name” and “age” parameters.

greetUser("John", 30);

This will log the following message to the console:

Hello John, your age is 30

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply