1

I have following arrow function.

var a = 10;
var b = 5;
var str = (a,b) => ("sum: "+(a+b));

str();

I expected the output to be

sum: 15

but the output is

sum: NaN

why?

2
  • var a = 10; var b = 5; var str = (a,b) str = a+b; 15 Commented Jan 11, 2017 at 5:30
  • 2
    you need to pass the arguments str(a, b); Commented Jan 11, 2017 at 5:30

3 Answers 3

2
var a = 10;

var b = 5;

var str = (a, b) => ("sum: " + (a + b));

str(a, b); // You have to call the function with parameters. 
Sign up to request clarification or add additional context in comments.

Comments

1

You are not passing the arguments a and b in call to function

var a = 10;
var b = 5;
var str = (a, b) => ("sum: " + (a + b));
console.log(str(a, b));

Comments

1

You have to pass parameters str(a,b).

var a = 10;
var b = 5;
var str = (a,b) => ("sum: "+(a+b));

str(a,b);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.