0

I am trying to access the value of inner function variable outside. But I cannot use it outside the inner function. My code is-

function t9(){
   var start=298;
   var diff;
   function count(){
      var end=400;
      var diff=end-start;
   } 
   return diff;
}
2
  • 2
    You're declaring count, but never calling it. Is that intentional? Commented Apr 12, 2014 at 7:07
  • how you are calling t9() and count().. It depends Commented Apr 12, 2014 at 7:28

3 Answers 3

4

Dont re-declare the variable, so instead of : var diff=end-start; write- diff=end-start;

Thats it

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

Comments

0
function t9()
  var start=298;
  return count(start);
}

function count(start){
   var end=400;
   var diff=end-start;
   return diff;
  } 

Comments

0
function t9(){
   var start=298;
   var diff;
   var end;
   function count(){

      end=400;
      diff=end-start;
   } 
   count();
   alert(diff);
}
t9();

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.