DEV Community

Vaman
Vaman

Posted on • Updated on

Parameters and Arguments

Yeah!! this post is regarding parameters and argument

Parameters are variables in the declaration of the function.
Arguments are the actual value of the variable that's getting passed to the function.

For example:

  • The below function does not take any parameters and called as parameterless function or function with no parameter
function ShowNameinConsole ()
{
    console.log("My name is : xyz")
}
//all you need to do is call the function to see the printed message
ShowNameinConsole()
Enter fullscreen mode Exit fullscreen mode
  • Function with parameters: One can provide as many numbers of parameters required for the function
function SingleParam(Param1) //Here Param1 is parameter, 
// SingleParam function takes single parameter
{
    console.log("My name is :" + Param1)
}
// again do not forget to call the function
SingleParam("xyz") // here "xyz" is called as argument
Enter fullscreen mode Exit fullscreen mode
// javascript provides flexibility to pass arguments to a non-parametric function
function ShowNameinConsole ()
{
    for (let i = 0; i < arguments.length; i++) 
    {
        console.log(arguments[i]);
    }
}
// however this is not a recommended way of programming as other languages do not provide such freedom
Enter fullscreen mode Exit fullscreen mode

Here my post ends 😄

Top comments (0)