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

后端 未结 5 2049
野趣味
野趣味 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:21

    As you already mentioned, return gives you the possibility to call a function and save its returning value.

    Here is a little example:

    function bla(x) { return "blablabla"; }
    

    If I call the method I will get a string with blablabla:

    var blastring = bla(x);
    alert(blastring);
    

    This would result in an alert with blablabla.

提交回复
热议问题