Passing a local variable from one function to another

后端 未结 3 513
独厮守ぢ
独厮守ぢ 2021-01-30 09:29

I am a beginner in JavaScript and wanted to ask the following: I have two simple functions and was wondering if there is any way to pass a variable value from one function to an

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-30 10:06

    Adding to @pranay-rana's list:

    Third way is:

    function passFromValue(){
        var x = 15;
        return x;  
    }
    function passToValue() {
        var y = passFromValue();
        console.log(y);//15
    }
    passToValue(); 
    

提交回复
热议问题