js pass value from one function to another

Everyone uses a function call. Today, when I was calling the interface, I suddenly found that I needed to refer to the value obtained in another function.

 

for example

At the beginning, I called like this 

<script type="text/javascript">
    function a(){
    	var b = 'hello world';
    	return b;
    }
    function c(){
    	return a();
    }
    alert(c());
</script>

   The alert pops up is hello world.

 

But I still have a function inside the a function, the style is like this

<script type="text/javascript">
    function a(){
    	function aa(){
    		var b = 'hello world';
    		return b;
    	}
    }
    function c(){
    	return a();
    }
    alert(c());
</script>

   This time the alert comes out of the desired b value, but undefined! !

   Analysis: When I was here, what I got was always undefined, and when I looked back, I could find that

            The b in the aa function needs to be returned. When returning for the first time, b is undoubtedly passed to a. But the value in a is not passed out, so there is the next step 

<script type="text/javascript">
    function a(){
    	function aa(){
    		var b = 'hello world';
    		return b;
    	}
    	return aa();
    }
    function c(){
    	return a();
    }
    alert(c());
</script>

    Now the alert comes out is the hello world we want~~ 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326163144&siteId=291194637