When to use return, and what happens to returned data?

后端 未结 5 2043
野趣味
野趣味 2021-02-01 07:50

What is the difference between:

function bla1(x){console.log(x)}

and

function bla(x){return console.log(x)}

I

5条回答
  •  遇见更好的自我
    2021-02-01 08:11

    Return in a function is a way to pass back data from the function.

    Example:

    function test(){
       var test = 1+1;
       return test;
    }
    
    var feedback = test(); //feedback would now contain the value 2 if outputted.
    

    We could also send a variable into the function and then return it back out.

    Example 2:

     function test(i){
        i= i+1;
        return i;
     }
    
     var feedback = test(1); //feedback would also output the value 2.
    

提交回复
热议问题