Passing Value to Functions with Arguments

This I dont know how to solve:- You should call functionWithArgs with two numbers after you define it.

Your code so far


function functionWithArgs(a, b){
console.log(a+b);
}
functionWithArgs(1+2);
functionWithArgs(7+9);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36.

Challenge: Passing Values to Functions with Arguments

Link to the challenge:

Actually you are using expression 2+1 is actually one argument but if you use 2, 1 that is two arguments.

2+1, 2+2 that will be two argument because at run time expression returns single value.

Will you elaborate more?

Hello!

Hmmm… I’ll try to explain it.

The challenge is asking you to pass two arguments to the function.

But, what’s an argument? An argument is any value (string, object, number) you pass to a function. Depending on the function (and language), it may accept from 0 to any number of arguments. In this case, the function expects two arguments. To pass more than one argument, you separate them using commas.

The problem with your code

1 + 2 is not an argument, it’s an expression, and the result of that expression gets passed to the function as a single argument.

Basically, the sum is executed before it’s passed to the function, hence it counts a single argument.

So, with that definition, how many arguments are passed to a function call like this myFunction(1+2, 1+1+1+1)?

2 Likes

functionWithArgs(1+2)

you are using this which is actually equals to functionWithArgs(3, ?) so where is second argument.

in short you always pass arguments sperated with commas

1 Like

Thanks for your help.

Thank you very much for explaination.

1 Like