Saturday, 30 November 2024

Function Parameters and Arguments in JavaScript

Functions can take input values known as parameters. When you call the function, you pass in arguments to those parameters.

 

  • Parameters are the variables defined in a function's signature that specify what kind of inputs the function expects.
  • Arguments are the actual values you pass into the function when calling it.

 

Here’s an example:

 

parameterizedFunctions.js

function greetUser(name) {
    console.log("Hello, " + name + "!!!!!");
}

greetUser("Krishna"); 
greetUser("Hari");

Output

Hello, Krishna!!!!!
Hello, Hari!!!!!

In this example,

1.   name is a parameter.

2.   "Krishna" and "Hari" are arguments passed to the name parameter when calling the function.

Previous                                                    Next                                                    Home

No comments:

Post a Comment