【问题标题】:How to return a functions output如何返回函数输出
【发布时间】:2021-02-14 15:38:39
【问题描述】:

函数 output(string*[1])* 带有下划线。我不明白为什么它不返回 E。

    function output(string[1]) {
    
    }
    
    return output;
    
 }
 countBs("hello")

【问题讨论】:

  • 代码是function countBs(string){ countBs[count]; } countBs("hello") function countBs(string){ function string[count]{ if } }
  • function output(string[1]) { 是无效语法,function output(string) { 是。

标签: javascript function return


【解决方案1】:

您的问题不完整,难以回答。请发布完整的问题,其中包含可以由尝试回答您问题的人运行的完整代码。

我不确定我是否理解正确。 您定义一个新函数。在函数定义中,您可以通过告知其名称来声明其形参(此处没有赋值)。在这个例子中function output(str, index) 的形式参数是 'str' 和 'index'。

在使用函数时,您使用 实际参数 调用它,这意味着您将值分配给形式参数:output("hello", 1)

这里是完整的源代码:

function output(str, index) {
        return str[index];
}

ret = output("hello", 1);
console.log("value: " + ret);

【讨论】:

    猜你喜欢
    • 2015-02-23
    • 2022-10-07
    • 2017-08-09
    • 2016-09-28
    • 2014-09-22
    • 2022-12-31
    • 2013-03-01
    • 2019-02-07
    • 2011-11-25
    相关资源
    最近更新 更多