Parameters and Arguments
Vaman
Posted on August 16, 2020
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()
- 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
// 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
Here my post ends 😄
💖 💪 🙅 🚩
Vaman
Posted on August 16, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.