Return value from nested function in Javascript

Posted by Chris Armstrong on Stack Overflow See other posts from Stack Overflow or by Chris Armstrong
Published on 2010-04-10T02:15:30Z Indexed on 2010/04/10 2:23 UTC
Read the original article Hit count: 480

I have a function that is set up as follows

function mainFunction() {
      function subFunction() {
            var str = "foo";
            return str;
      }
}

var test = mainFunction();
alert(test);

To my logic, that alert should return 'foo', but instead it returns undefined. What am I doing wrong?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about return-value