0

Here is my code i want alert to give (some data) value. which is of inner function it give undefined value

alert(f1());
function f1(){
  f2(function (){
    return "some data";    
  });
}
function f2(f4){
  // some code
}

visit : https://jsfiddle.net/dvdhyttr/8/

i want alert get value (some data). but getting undefined.

1
  • 1
    You have to be more descriptive about what you want, the question is unintelligible. Is this what you want? Commented Mar 30, 2018 at 19:23

2 Answers 2

1

Two main issues

  • Missing return within the function f1
  • Within function f2 you need to return the result of calling the function f4.

alert(f1());

function f1() {
  return f2(function() {
    return "some data";
  });
}

function f2(f4) {
  return f4()
}

Sign up to request clarification or add additional context in comments.

Comments

0

You need to assign the return values of the functions to variables in the outer function and return them, all the way up to alert(f1());.

alert(f1());

function f1() {
  const resultOfF2 = f2(function() {
    return "some data";
  });
  return resultOfF2;
}

function f2(f4) {
  return f4();
  // some code
}

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.