• <bdo id='3XGgW'></bdo><ul id='3XGgW'></ul>
  • <i id='3XGgW'><tr id='3XGgW'><dt id='3XGgW'><q id='3XGgW'><span id='3XGgW'><b id='3XGgW'><form id='3XGgW'><ins id='3XGgW'></ins><ul id='3XGgW'></ul><sub id='3XGgW'></sub></form><legend id='3XGgW'></legend><bdo id='3XGgW'><pre id='3XGgW'><center id='3XGgW'></center></pre></bdo></b><th id='3XGgW'></th></span></q></dt></tr></i><div id='3XGgW'><tfoot id='3XGgW'></tfoot><dl id='3XGgW'><fieldset id='3XGgW'></fieldset></dl></div>

      <small id='3XGgW'></small><noframes id='3XGgW'>

      <tfoot id='3XGgW'></tfoot>

        <legend id='3XGgW'><style id='3XGgW'><dir id='3XGgW'><q id='3XGgW'></q></dir></style></legend>
      1. 何时使用 return,返回的数据会发生什么?

        时间:2023-09-04
          <tbody id='e9upX'></tbody>

        <small id='e9upX'></small><noframes id='e9upX'>

      2. <i id='e9upX'><tr id='e9upX'><dt id='e9upX'><q id='e9upX'><span id='e9upX'><b id='e9upX'><form id='e9upX'><ins id='e9upX'></ins><ul id='e9upX'></ul><sub id='e9upX'></sub></form><legend id='e9upX'></legend><bdo id='e9upX'><pre id='e9upX'><center id='e9upX'></center></pre></bdo></b><th id='e9upX'></th></span></q></dt></tr></i><div id='e9upX'><tfoot id='e9upX'></tfoot><dl id='e9upX'><fieldset id='e9upX'></fieldset></dl></div>

            <legend id='e9upX'><style id='e9upX'><dir id='e9upX'><q id='e9upX'></q></dir></style></legend>
              <tfoot id='e9upX'></tfoot>
                <bdo id='e9upX'></bdo><ul id='e9upX'></ul>
                  本文介绍了何时使用 return,返回的数据会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  有什么区别:

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

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

                  在什么情况下应该使用return?

                  In which cases should I use return?

                  另外,当一个函数返回一个值时,它会发生什么?它存储在某个地方吗?

                  also, when a value is returned from a function, what happens to it? is it stored somewhere?

                  推荐答案

                  有什么区别

                  第一个函数返回 undefined(因为它没有明确地 return 任何内容),第二个函数返回 console.log 返回的任何内容.

                  The first function returns undefined (as it does not return anything explicitly), the second one returns whatever console.log returns.

                  什么情况下应该使用return?

                  In which cases should I use return?

                  当函数正在生成某个值并且您想将其传递回调用者时.以 Math.pow 为例.它接受两个参数,基数和指数,并将基数返回到指数.

                  When the function is generating some value and you want to pass it back to the caller. Take Math.pow for example. It takes two arguments, the base and the exponent and returns the base raised to the exponent.

                  当一个值从一个函数返回时,它会发生什么?它存储在某个地方吗?

                  When a value is returned from a function, what happens to it? is it stored somewhere?

                  如果要存储返回值,则必须将其分配给变量

                  If you want to store the return value, then you have to assign it to a variable

                  var value = someFunction();
                  

                  这会将 someFunction 的返回值存储在 value 中.如果您在没有分配返回值的情况下调用该函数,则该值将被静默删除:

                  This stores the return value of someFunction in value. If you call the function without assigning the return value, then the value is just silently dropped:

                  someFunction();
                  

                  <小时>

                  这些是编程基础知识,不仅与 JavaScript 相关.你应该找到一本介绍这些基础知识的书,尤其是关于 JavaScript 的书,我建议阅读 MDN JavaScript 指南.也许关于 函数 的维基百科文章也有帮助.


                  These are programming basics and are not only relevant to JavaScript. You should find a book which introduces these basics and in particular for JavaScript, I recommend to read the MDN JavaScript Guide. Maybe the Wikipedia article about Functions is helpful as well.

                  这篇关于何时使用 return,返回的数据会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何捕获在包含多个表单的页面上按下的输入键? 下一篇:从 jquery ajax 调用分配变量返回未定义

                  相关文章

                • <small id='el07S'></small><noframes id='el07S'>

                    <tfoot id='el07S'></tfoot>

                      <i id='el07S'><tr id='el07S'><dt id='el07S'><q id='el07S'><span id='el07S'><b id='el07S'><form id='el07S'><ins id='el07S'></ins><ul id='el07S'></ul><sub id='el07S'></sub></form><legend id='el07S'></legend><bdo id='el07S'><pre id='el07S'><center id='el07S'></center></pre></bdo></b><th id='el07S'></th></span></q></dt></tr></i><div id='el07S'><tfoot id='el07S'></tfoot><dl id='el07S'><fieldset id='el07S'></fieldset></dl></div>
                      • <bdo id='el07S'></bdo><ul id='el07S'></ul>

                      <legend id='el07S'><style id='el07S'><dir id='el07S'><q id='el07S'></q></dir></style></legend>