How can I change the function passed params?

how to pass parameter in javascript function from html
function arguments javascript
pass parameter to javascript function onclick
javascript pass function as parameter with arguments
javascript pass variable number of arguments to function
javascript function parameter default value
pass multiple parameters in javascript function
pass multiple parameters to javascript function onclick

How can I change the function passed params?

function minus_num(num) {
  num -= 1
}

var num_test = 10

while (num > 0){
  minus_num(num_test)
}

console.log(num)  // there I want to get the 0, but it is infinite loop, because the `num` will have a copy in the function.

How can I change the num_test itself?

You need the function to return the value after being subtracted, and then you need to assign the result of that to num_test.

But num is never explicitly declared in your code. You probably wanted to put num_test in the loop instead:

function minus_num(num) {
  return num - 1
}

var num_test = 10

while (num_test > 0){
  num_test = minus_num(num_test)
}

console.log(num_test)

JavaScript: Don't Reassign Your Function Arguments, Did you know that a JavaScript function's named parameter variables are synonyms for the providing a default for the first argument if only two are passed. Strangely, all of the values in the result object are set to "green" . Passing Extra Parameters Extra Parameters, Fixed Variables, or Data. Sometimes objective or constraint functions have parameters in addition to the independent variable. The extra parameters can be data, or can represent variables that do not change during the optimization. There are three methods of passing these parameters:

Primitives are passed by value, so you cannot change them in place. Instead you must return the changed value from the function and assign it back to the same variable:

function minus_num(num) {
  num -= 1;
  return num;
}

var num_test = 10

while (num_test > 0) {
  num_test = minus_num(num_test)
}

console.log(num_test);

C Parameter passing, The actual parameter cannot be changed by function. "In" parameter. By-​Reference An address gets sent to function. The function can change the values at that  The parameters, in a function call, are the function's arguments. JavaScript arguments are passed by value: The function only gets to know the values, not the argument's locations. If a function changes an argument's value, it does not change the parameter's original value. Changes to arguments are not visible (reflected) outside the function.

I think it should be

function minus_num(num) {
   return num - 1
}

var num_test = 10

while (num_test > 0){
  num_test = minus_num(num_test)
}

console.log(num_test) 

How To Use ES6 Arguments And Parameters, When an array is passed to the Math.max() function, it throws an error. If there are no arguments, the rest parameter will be set to an empty  params – passed to main function is a JSON object that holds parameters (input) to this cloud function. To tests this cloud function with a parameter, click Change Input button above the code editor.

JavaScript Function Parameters, JavaScript functions do not perform type checking on the passed arguments. missing arguments (less than declared), the missing values are set to: undefined. want to pass this array to inner function with a params-array (e. g. string.format). When i've passed an integer to the outer function, the string.format sets the string-value "System.Object[]" at the position of {0}. How can i get it work, so that all my values, passed to the outer function, will inserted by string.format, like i've passed it

The Beginner's Guide to JavaScript Default Parameters, It means that if you don't pass the arguments to the function, its parameters an easier way to set the default values for the parameters of a function as shown in  The object reference is passed to the function parameters. They can't be changed within the function, because they can't be changed at all, i.e. they are immutable. It's different, if we pass mutable arguments. They are also passed by object reference, but they can be changed in place in the function.

Fancy Function Parameters, But, just because function parameters are so fundamental doesn't mean is that the function renders a list — but the rest of the arguments passed don't set defaults for optional parameters if(typeof ordered === undefined)  Parameters and Results. While each message (for more information see Messages) is identified by a single word—the message name—it can also include additional information in the form of parameters. Parameters are values that are passed to commands or functions. The command put "Hello, World!"

Comments
  • It's good practice not to change argument inside function body. Preferred option is return num - 1; as @CertainPerformance anwser.