Reputation: 17
This is my code:
var i=5;
var j=5;
function sum(n,m){
var num = n + m ;
alert(num);
};
sum(i+j);
When I run it, it should return '10', but it returns
NaN
.
Please help me with what I'm doing wrong.
Upvotes: 0
Views: 50
Reputation: 17
I figured what I was doing wrong.
this below code works -
var i=5;
var j=5;
function sum(n,m){
var num = n + m ;
alert(num);
};
sum(i, j);
Upvotes: 0
Reputation: 15166
Change it from sum(i + j)
to sum(i, j)
. So technically your code was passing originally like sum(10, undefined)
which resolved as NaN
.
var i=5;
var j=5;
function sum(n,m){
var num = n + m ;
alert(num);
};
sum(i, j);
I hope that helps!
Upvotes: 3