I think the main problem here is a misunderstanding as to how parameters work in JavaScript. It looks like you come from a language where this statement:
my_func(param01=1)
Would pass a parameter called param0 with the value 1 to the function.
But in JavaScript this is what happens:
- param01 is a variable outside of your function and you assign
1 to it
- The result of that assignment expression is
1 so 1 is also passed the the function as a parameter
This explains why param01 is also 1 outside of your function.
In JavaScript you don't specify the parameter names when calling your function. So this works just the same:
my_func(1)
If you want to provide more parameters you have multiple options:
- You simply separate them with a comma:
my_func(1, 2, 3, 4, 5, 6)
Your function declaration must then look like this:
function my_func(param1, param2, param3, param4, param5, param6)
Or you could use the rest parameter syntax:
function my_func(...params)
This way you can pass as many arguments as you like and they will all be in the params array. You can then access them like this: param[0] for the first parameter, param[1] for the second and so on.
- You can create an array with your values and pass the array as a parameter:
const parameters = [1, 2, 3, 4, 5 ,6];
my_func(parameters)
Your function declaration must then look like this:
function my_func(params)
As a side note on clean coding: Your function should have as few parameters as possible. If you have a lot of parameters this usually indicates that the function is doing too many things, thence violates the single responsibility pattern and should be split up into smaller functions.