为JavaScript函数设置默认参数值。

时间:2022-09-11 17:08:59

I would like a JavaScript function to have optional arguments which I set a default on, which gets used if the value isn't defined. In Ruby you can do it like this:

我希望JavaScript函数具有可选参数,我设置了一个默认值,如果没有定义值,则使用它。在Ruby中,你可以这样做:

def read_file(file, delete_after = false)
  # code
end

Does this work in JavaScript?

这在JavaScript中有用吗?

function read_file(file, delete_after = false) {
  // Code
}

13 个解决方案

#1


2853  

From ES6/ES2015, default parameters is in the language specification.

从ES6/ES2015,默认参数在语言规范中。

function read_file(file, delete_after = false) {
  // Code
}

just works.

只是工作。

Reference: Default Parameters - MDN

参考:默认参数- MDN。

Default function parameters allow formal parameters to be initialized with default values if no value or undefined is passed.

默认函数参数允许使用默认值初始化参数,如果不通过任何值或未定义的值。

You can also simulate default named parameters via destructuring:

您还可以通过破坏来模拟默认的命名参数:

// the `= {}` below lets you call the function without any parameters
function myFor({ start = 5, end = 1, step = -1 } = {}) { // (A)
    // Use the variables `start`, `end` and `step` here
    ···
}

Pre ES2015,

ES2015之前,

There are a lot of ways, but this is my preferred method - it lets you pass in anything you want, including false or null. (typeof null == "object")

有很多方法,但这是我喜欢的方法——它允许你传递任何你想要的东西,包括false或null。(typeof null = =“对象”)

function foo(a, b) {
  a = typeof a !== 'undefined' ? a : 42;
  b = typeof b !== 'undefined' ? b : 'default_b';
  ...
}

#2


548  

function read_file(file, delete_after) {
    delete_after = delete_after || "my default here";
    //rest of code
}

This assigns to delete_after the value of delete_after if it is not a falsey value otherwise it assigns the string "my default here". For more detail, check out Doug Crockford's survey of the language and check out the section on Operators.

这个赋值在delete_after的值之后,如果它不是一个falsey值,否则它会将字符串赋值为“my default here”。要了解更多细节,请查看Doug Crockford对语言的调查,并查看关于操作符的部分。

This approach does not work if you want to pass in a falsey value i.e. false, null, undefined, 0 or "". If you require falsey values to be passed in you would need to use the method in Tom Ritter's answer.

如果您想传递一个falsey值,即false、null、未定义、0或“”,则此方法不起作用。如果需要传入falsey值,则需要在Tom Ritter的回答中使用该方法。

When dealing with a number of parameters to a function, it is often useful to allow the consumer to pass the parameter arguments in an object and then merge these values with an object that contains the default values for the function

在处理函数的多个参数时,允许使用者将参数参数传递到对象中,然后将这些值与包含该函数的默认值的对象合并在一起,通常是有用的。

function read_file(values) {
    values = merge({ 
        delete_after : "my default here"
    }, values || {});

    // rest of code
}

// simple implementation based on $.extend() from jQuery
function merge() {
    var obj, name, copy,
        target = arguments[0] || {},
        i = 1,
        length = arguments.length;

    for (; i < length; i++) {
        if ((obj = arguments[i]) != null) {
            for (name in obj) {
                copy = obj[name];

                if (target === copy) {
                    continue;
                }
                else if (copy !== undefined) {
                    target[name] = copy;
                }
            }
        }
    }

    return target;
};

to use

使用

// will use the default delete_after value
read_file({ file: "my file" }); 

// will override default delete_after value
read_file({ file: "my file", delete_after: "my value" }); 

#3


133  

I find something simple like this to be much more concise and readable personally.

我发现一些简单的东西,像这样更简洁,更容易读懂。

function pick(arg, def) {
   return (typeof arg == 'undefined' ? def : arg);
}

function myFunc(x) {
  x = pick(x, 'my default');
} 

#4


51  

In ECMAScript 6 you will actually be able to write exactly what you have:

在ECMAScript 6中,你实际上能够写出你所拥有的:

function read_file(file, delete_after = false) {
  // Code
}

This will set delete_after to false if it s not present or undefined. You can use ES6 features like this one today with transpilers such as Babel.

如果不存在或未定义,这将设置delete_after为false。您可以使用像今天这样的ES6特性,比如像Babel这样的传输器。

See the MDN article for more information.

有关更多信息,请参见MDN文章。

#5


16  

Default Parameter Values

默认参数值

With ES6, you can do perhaps one of the most common idioms in JavaScript relates to setting a default value for a function parameter. The way we’ve done this for years should look quite familiar:

使用ES6,您可以使用JavaScript中最常见的一个习惯用语,它涉及为函数参数设置默认值。我们多年来的做法应该很熟悉:

function foo(x,y) {
 x = x || 11;
 y = y || 31;
 console.log( x + y );
}
foo(); // 42
foo( 5, 6 ); // 11
foo( 5 ); // 36
foo( null, 6 ); // 17

This pattern is most used, but is dangerous when we pass values like

这种模式是最常用的,但是当我们传递值时是很危险的。

foo(0, 42)
foo( 0, 42 ); // 53 <-- Oops, not 42

Why? Because the 0 is falsy, and so the x || 11 results in 11, not the directly passed in 0. To fix this gotcha, some people will instead write the check more verbosely like this:

为什么?因为0是假的,所以x || 11的结果是11,不是直接通过0。为了解决这个问题,有些人反而会更像这样写:

function foo(x,y) {
 x = (x !== undefined) ? x : 11;
 y = (y !== undefined) ? y : 31;
 console.log( x + y );
}
foo( 0, 42 ); // 42
foo( undefined, 6 ); // 17

we can now examine a nice helpful syntax added as of ES6 to streamline the assignment of default values to missing arguments:

我们现在可以检查一种非常有用的语法,该语法添加到ES6中,以简化默认值的分配,以减少参数的丢失:

function foo(x = 11, y = 31) {
 console.log( x + y );
}

foo(); // 42
foo( 5, 6 ); // 11
foo( 0, 42 ); // 42
foo( 5 ); // 36
foo( 5, undefined ); // 36 <-- `undefined` is missing
foo( 5, null ); // 5 <-- null coerces to `0`
foo( undefined, 6 ); // 17 <-- `undefined` is missing
foo( null, 6 ); // 6 <-- null coerces to `0`

x = 11 in a function declaration is more like x !== undefined ? x : 11 than the much more common idiom x || 11

在函数声明中,x = 11更像x !==未定义?x: 11比更常见的习语x || 11。

Default Value Expressions

默认值表达式

Function default values can be more than just simple values like 31; they can be any valid expression, even a function call:

函数默认值可以不仅仅是简单的值,比如31;它们可以是任何有效表达式,甚至是函数调用:

function bar(val) {
 console.log( "bar called!" );
 return y + val;
}
function foo(x = y + 3, z = bar( x )) {
 console.log( x, z );
}
var y = 5;
foo(); // "bar called"
 // 8 13
foo( 10 ); // "bar called"
 // 10 15
y = 6;
foo( undefined, 10 ); // 9 10

As you can see, the default value expressions are lazily evaluated, meaning they’re only run if and when they’re needed — that is, when a parameter’s argument is omitted or is undefined.

如您所见,默认值表达式被延迟地评估,这意味着它们只在需要时才运行——也就是说,当一个参数的参数被省略或未定义时。

A default value expression can even be an inline function expression call — commonly referred to as an Immediately Invoked Function Expression (IIFE):

默认值表达式甚至可以是内联函数表达式调用——通常称为立即调用的函数表达式(IIFE):

function foo( x =
 (function(v){ return v + 11; })( 31 )
) {
 console.log( x );
}
foo(); // 42

#6


8  

that solution is work for me in js:

这个解决方案对我来说是用js:

function read_file(file, delete_after) {
    delete_after = delete_after || false;
    // Code
}

#7


5  

Just use an explicit comparison with undefined.

只需要使用显式的比较与未定义。

function read_file(file, delete_after)
{
    if(delete_after === undefined) { delete_after = false; }
}

#8


5  

being a long time C++ developer (Rookie to web development :)), when I first came across this situation, I did the parameter assignment in the function definition, like it is mentioned in the question, as follows.

当我第一次遇到这种情况时,我在函数定义中做了参数赋值,就像问题中提到的那样。

function myfunc(a,b=10)

But beware that it doesn't work consistently across browsers. For me it worked on chrome on my desktop, but did not work on chrome on android. Safer option, as many have mentioned above is -

但是要注意的是,它在不同的浏览器之间并不是一致的。对我来说,它在我的桌面上使用了chrome,但没有在android上使用chrome。更安全的选择,正如许多人所提到的那样。

    function myfunc(a,b)
    {
    if (typeof(b)==='undefined') b = 10;
......
    }

Intention for this answer is not to repeat the same solutions, what others have already mentioned, but to inform that parameter assignment in the function definition may work on some browsers, but don't rely on it.

这个答案的意图不是重复相同的解决方案,其他的已经提到过,但是要告知函数定义中的参数赋值可以在一些浏览器上运行,但是不要依赖它。

#9


4  

As an update...with ECMAScript 6 you can FINALLY set default values in function parameter declarations like so:

作为一个更新……通过ECMAScript 6,您可以最终在函数参数声明中设置默认值:

function f (x, y = 7, z = 42) {
  return x + y + z
}

f(1) === 50

As referenced by - http://es6-features.org/#DefaultParameterValues

引用- http://es6-features.org/#DefaultParameterValues。

#10


4  

To anyone interested in having there code work in Microsoft Edge, do not use defaults in function parameters.

对于任何对在Microsoft Edge中使用代码工作感兴趣的人来说,不要在函数参数中使用默认值。

function read_file(file, delete_after = false) {
    #code
}

In that example Edge will throw an error "Expecting ')'"

在这个示例中,Edge将抛出一个“期望”错误。

To get around this use

来解决这个问题。

function read_file(file, delete_after) {
  if(delete_after == undefined)
  {
    delete_after = false;
  }
  #code
}

As of Aug 08 2016 this is still an issue

截至2016年8月8日,这仍是一个问题。

#11


3  

I would highly recommend extreme caution when using default parameter values in javascript. It often creates bugs when used in conjunction with higher order functions like forEach, map, and reduce. For example, consider this line of code:

在javascript中使用默认参数值时,我强烈推荐使用极端谨慎。它经常在与更高阶函数(如forEach、map和reduce)一起使用时产生错误。例如,考虑这一行代码:

['1', '2', '3'].map(parseInt); // [1, NaN, NaN]

parseInt has an optional second parameter function parseInt(s, [radix=10]) but map calls parseInt with three arguments: (element, index, and array).

parseInt有一个可选的第二个参数函数parseInt(s, [radix=10]),但是映射调用parseInt有三个参数:(元素、索引和数组)。

I suggest you separate your required parameters form your optional/default valued arguments. If your function takes 1,2, or 3 required parameters for which no default value makes sense, make them positional parameters to the function, any optional parameters should follow as named attributes of a single object. If your function takes 4 or more, perhaps it makes more sense to supply all arguments via attributes of a single object parameter.

我建议您将必需的参数与可选/默认值参数分开。如果您的函数使用了1、2或3个没有默认值的必需参数,那么将这些参数设置为该函数的位置参数,任何可选参数都应该作为单个对象的命名属性。如果您的函数需要4个或更多,那么通过单个对象参数的属性提供所有参数可能更有意义。

In your case I would suggest you write your deleteFile function like this:

在你的案例中,我建议你这样写你的deleteFile函数:

// unsafe
function read_file(fileName, deleteAfter=false) {
    if (deleteAfter) {
        console.log(`Reading and then deleting ${fileName}`);
    } else {
        console.log(`Just reading ${fileName}`);
    }
}

// better
function readFile(fileName, options={}) {
  const { deleteAfter = false } = options || {}; // if null
  read_file(fileName, deleteAfter);
}

console.log('unsafe...');
['log1.txt', 'log2.txt', 'log3.txt'].map(read_file);

console.log('better...');
['log1.txt', 'log2.txt', 'log3.txt'].map(readFile);

Running the above snippet illustrates the dangers lurking behind default argument values for unused parameters.

运行上面的代码片段说明了未使用参数的默认参数值背后隐藏的危险。

#12


0  

As per the syntax

按照语法

function [name]([param1[ = defaultValue1 ][, ..., paramN[ = defaultValueN ]]]) {
   statements
}

you can define the default value of formal parameters. and also check undefined value by using typeof function.

您可以定义正式参数的默认值。还可以使用类型函数检查未定义的值。

#13


-3  

Yes, This will work in Javascript. You can also do that:

是的,这将在Javascript中使用。你也可以这样做:

function func(a=10,b=20)
{
    alert (a+' and '+b);
}

func(); // Result: 10 and 20

func(12); // Result: 12 and 20

func(22,25); // Result: 22 and 25

#1


2853  

From ES6/ES2015, default parameters is in the language specification.

从ES6/ES2015,默认参数在语言规范中。

function read_file(file, delete_after = false) {
  // Code
}

just works.

只是工作。

Reference: Default Parameters - MDN

参考:默认参数- MDN。

Default function parameters allow formal parameters to be initialized with default values if no value or undefined is passed.

默认函数参数允许使用默认值初始化参数,如果不通过任何值或未定义的值。

You can also simulate default named parameters via destructuring:

您还可以通过破坏来模拟默认的命名参数:

// the `= {}` below lets you call the function without any parameters
function myFor({ start = 5, end = 1, step = -1 } = {}) { // (A)
    // Use the variables `start`, `end` and `step` here
    ···
}

Pre ES2015,

ES2015之前,

There are a lot of ways, but this is my preferred method - it lets you pass in anything you want, including false or null. (typeof null == "object")

有很多方法,但这是我喜欢的方法——它允许你传递任何你想要的东西,包括false或null。(typeof null = =“对象”)

function foo(a, b) {
  a = typeof a !== 'undefined' ? a : 42;
  b = typeof b !== 'undefined' ? b : 'default_b';
  ...
}

#2


548  

function read_file(file, delete_after) {
    delete_after = delete_after || "my default here";
    //rest of code
}

This assigns to delete_after the value of delete_after if it is not a falsey value otherwise it assigns the string "my default here". For more detail, check out Doug Crockford's survey of the language and check out the section on Operators.

这个赋值在delete_after的值之后,如果它不是一个falsey值,否则它会将字符串赋值为“my default here”。要了解更多细节,请查看Doug Crockford对语言的调查,并查看关于操作符的部分。

This approach does not work if you want to pass in a falsey value i.e. false, null, undefined, 0 or "". If you require falsey values to be passed in you would need to use the method in Tom Ritter's answer.

如果您想传递一个falsey值,即false、null、未定义、0或“”,则此方法不起作用。如果需要传入falsey值,则需要在Tom Ritter的回答中使用该方法。

When dealing with a number of parameters to a function, it is often useful to allow the consumer to pass the parameter arguments in an object and then merge these values with an object that contains the default values for the function

在处理函数的多个参数时,允许使用者将参数参数传递到对象中,然后将这些值与包含该函数的默认值的对象合并在一起,通常是有用的。

function read_file(values) {
    values = merge({ 
        delete_after : "my default here"
    }, values || {});

    // rest of code
}

// simple implementation based on $.extend() from jQuery
function merge() {
    var obj, name, copy,
        target = arguments[0] || {},
        i = 1,
        length = arguments.length;

    for (; i < length; i++) {
        if ((obj = arguments[i]) != null) {
            for (name in obj) {
                copy = obj[name];

                if (target === copy) {
                    continue;
                }
                else if (copy !== undefined) {
                    target[name] = copy;
                }
            }
        }
    }

    return target;
};

to use

使用

// will use the default delete_after value
read_file({ file: "my file" }); 

// will override default delete_after value
read_file({ file: "my file", delete_after: "my value" }); 

#3


133  

I find something simple like this to be much more concise and readable personally.

我发现一些简单的东西,像这样更简洁,更容易读懂。

function pick(arg, def) {
   return (typeof arg == 'undefined' ? def : arg);
}

function myFunc(x) {
  x = pick(x, 'my default');
} 

#4


51  

In ECMAScript 6 you will actually be able to write exactly what you have:

在ECMAScript 6中,你实际上能够写出你所拥有的:

function read_file(file, delete_after = false) {
  // Code
}

This will set delete_after to false if it s not present or undefined. You can use ES6 features like this one today with transpilers such as Babel.

如果不存在或未定义,这将设置delete_after为false。您可以使用像今天这样的ES6特性,比如像Babel这样的传输器。

See the MDN article for more information.

有关更多信息,请参见MDN文章。

#5


16  

Default Parameter Values

默认参数值

With ES6, you can do perhaps one of the most common idioms in JavaScript relates to setting a default value for a function parameter. The way we’ve done this for years should look quite familiar:

使用ES6,您可以使用JavaScript中最常见的一个习惯用语,它涉及为函数参数设置默认值。我们多年来的做法应该很熟悉:

function foo(x,y) {
 x = x || 11;
 y = y || 31;
 console.log( x + y );
}
foo(); // 42
foo( 5, 6 ); // 11
foo( 5 ); // 36
foo( null, 6 ); // 17

This pattern is most used, but is dangerous when we pass values like

这种模式是最常用的,但是当我们传递值时是很危险的。

foo(0, 42)
foo( 0, 42 ); // 53 <-- Oops, not 42

Why? Because the 0 is falsy, and so the x || 11 results in 11, not the directly passed in 0. To fix this gotcha, some people will instead write the check more verbosely like this:

为什么?因为0是假的,所以x || 11的结果是11,不是直接通过0。为了解决这个问题,有些人反而会更像这样写:

function foo(x,y) {
 x = (x !== undefined) ? x : 11;
 y = (y !== undefined) ? y : 31;
 console.log( x + y );
}
foo( 0, 42 ); // 42
foo( undefined, 6 ); // 17

we can now examine a nice helpful syntax added as of ES6 to streamline the assignment of default values to missing arguments:

我们现在可以检查一种非常有用的语法,该语法添加到ES6中,以简化默认值的分配,以减少参数的丢失:

function foo(x = 11, y = 31) {
 console.log( x + y );
}

foo(); // 42
foo( 5, 6 ); // 11
foo( 0, 42 ); // 42
foo( 5 ); // 36
foo( 5, undefined ); // 36 <-- `undefined` is missing
foo( 5, null ); // 5 <-- null coerces to `0`
foo( undefined, 6 ); // 17 <-- `undefined` is missing
foo( null, 6 ); // 6 <-- null coerces to `0`

x = 11 in a function declaration is more like x !== undefined ? x : 11 than the much more common idiom x || 11

在函数声明中,x = 11更像x !==未定义?x: 11比更常见的习语x || 11。

Default Value Expressions

默认值表达式

Function default values can be more than just simple values like 31; they can be any valid expression, even a function call:

函数默认值可以不仅仅是简单的值,比如31;它们可以是任何有效表达式,甚至是函数调用:

function bar(val) {
 console.log( "bar called!" );
 return y + val;
}
function foo(x = y + 3, z = bar( x )) {
 console.log( x, z );
}
var y = 5;
foo(); // "bar called"
 // 8 13
foo( 10 ); // "bar called"
 // 10 15
y = 6;
foo( undefined, 10 ); // 9 10

As you can see, the default value expressions are lazily evaluated, meaning they’re only run if and when they’re needed — that is, when a parameter’s argument is omitted or is undefined.

如您所见,默认值表达式被延迟地评估,这意味着它们只在需要时才运行——也就是说,当一个参数的参数被省略或未定义时。

A default value expression can even be an inline function expression call — commonly referred to as an Immediately Invoked Function Expression (IIFE):

默认值表达式甚至可以是内联函数表达式调用——通常称为立即调用的函数表达式(IIFE):

function foo( x =
 (function(v){ return v + 11; })( 31 )
) {
 console.log( x );
}
foo(); // 42

#6


8  

that solution is work for me in js:

这个解决方案对我来说是用js:

function read_file(file, delete_after) {
    delete_after = delete_after || false;
    // Code
}

#7


5  

Just use an explicit comparison with undefined.

只需要使用显式的比较与未定义。

function read_file(file, delete_after)
{
    if(delete_after === undefined) { delete_after = false; }
}

#8


5  

being a long time C++ developer (Rookie to web development :)), when I first came across this situation, I did the parameter assignment in the function definition, like it is mentioned in the question, as follows.

当我第一次遇到这种情况时,我在函数定义中做了参数赋值,就像问题中提到的那样。

function myfunc(a,b=10)

But beware that it doesn't work consistently across browsers. For me it worked on chrome on my desktop, but did not work on chrome on android. Safer option, as many have mentioned above is -

但是要注意的是,它在不同的浏览器之间并不是一致的。对我来说,它在我的桌面上使用了chrome,但没有在android上使用chrome。更安全的选择,正如许多人所提到的那样。

    function myfunc(a,b)
    {
    if (typeof(b)==='undefined') b = 10;
......
    }

Intention for this answer is not to repeat the same solutions, what others have already mentioned, but to inform that parameter assignment in the function definition may work on some browsers, but don't rely on it.

这个答案的意图不是重复相同的解决方案,其他的已经提到过,但是要告知函数定义中的参数赋值可以在一些浏览器上运行,但是不要依赖它。

#9


4  

As an update...with ECMAScript 6 you can FINALLY set default values in function parameter declarations like so:

作为一个更新……通过ECMAScript 6,您可以最终在函数参数声明中设置默认值:

function f (x, y = 7, z = 42) {
  return x + y + z
}

f(1) === 50

As referenced by - http://es6-features.org/#DefaultParameterValues

引用- http://es6-features.org/#DefaultParameterValues。

#10


4  

To anyone interested in having there code work in Microsoft Edge, do not use defaults in function parameters.

对于任何对在Microsoft Edge中使用代码工作感兴趣的人来说,不要在函数参数中使用默认值。

function read_file(file, delete_after = false) {
    #code
}

In that example Edge will throw an error "Expecting ')'"

在这个示例中,Edge将抛出一个“期望”错误。

To get around this use

来解决这个问题。

function read_file(file, delete_after) {
  if(delete_after == undefined)
  {
    delete_after = false;
  }
  #code
}

As of Aug 08 2016 this is still an issue

截至2016年8月8日,这仍是一个问题。

#11


3  

I would highly recommend extreme caution when using default parameter values in javascript. It often creates bugs when used in conjunction with higher order functions like forEach, map, and reduce. For example, consider this line of code:

在javascript中使用默认参数值时,我强烈推荐使用极端谨慎。它经常在与更高阶函数(如forEach、map和reduce)一起使用时产生错误。例如,考虑这一行代码:

['1', '2', '3'].map(parseInt); // [1, NaN, NaN]

parseInt has an optional second parameter function parseInt(s, [radix=10]) but map calls parseInt with three arguments: (element, index, and array).

parseInt有一个可选的第二个参数函数parseInt(s, [radix=10]),但是映射调用parseInt有三个参数:(元素、索引和数组)。

I suggest you separate your required parameters form your optional/default valued arguments. If your function takes 1,2, or 3 required parameters for which no default value makes sense, make them positional parameters to the function, any optional parameters should follow as named attributes of a single object. If your function takes 4 or more, perhaps it makes more sense to supply all arguments via attributes of a single object parameter.

我建议您将必需的参数与可选/默认值参数分开。如果您的函数使用了1、2或3个没有默认值的必需参数,那么将这些参数设置为该函数的位置参数,任何可选参数都应该作为单个对象的命名属性。如果您的函数需要4个或更多,那么通过单个对象参数的属性提供所有参数可能更有意义。

In your case I would suggest you write your deleteFile function like this:

在你的案例中,我建议你这样写你的deleteFile函数:

// unsafe
function read_file(fileName, deleteAfter=false) {
    if (deleteAfter) {
        console.log(`Reading and then deleting ${fileName}`);
    } else {
        console.log(`Just reading ${fileName}`);
    }
}

// better
function readFile(fileName, options={}) {
  const { deleteAfter = false } = options || {}; // if null
  read_file(fileName, deleteAfter);
}

console.log('unsafe...');
['log1.txt', 'log2.txt', 'log3.txt'].map(read_file);

console.log('better...');
['log1.txt', 'log2.txt', 'log3.txt'].map(readFile);

Running the above snippet illustrates the dangers lurking behind default argument values for unused parameters.

运行上面的代码片段说明了未使用参数的默认参数值背后隐藏的危险。

#12


0  

As per the syntax

按照语法

function [name]([param1[ = defaultValue1 ][, ..., paramN[ = defaultValueN ]]]) {
   statements
}

you can define the default value of formal parameters. and also check undefined value by using typeof function.

您可以定义正式参数的默认值。还可以使用类型函数检查未定义的值。

#13


-3  

Yes, This will work in Javascript. You can also do that:

是的,这将在Javascript中使用。你也可以这样做:

function func(a=10,b=20)
{
    alert (a+' and '+b);
}

func(); // Result: 10 and 20

func(12); // Result: 12 and 20

func(22,25); // Result: 22 and 25