return和return()有什么区别? [英] What is the difference between return and return()?

查看:133
本文介绍了return和return()有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

function a() { return 1; }
function b() { return(1); }

我在Chrome的控制台中测试了上述代码,两者都返回 1

I tested the above code in Chrome's console, and both returned 1.

function c() { return "1"; }
function d() { return("1"); }

我还测试了上面的代码,并返回了两个函数 1

I also tested the code above, and both of the functions returned "1".

那么使用返回和<$ c之间有什么区别$ c> return()?

推荐答案

var i = 1 + 1;

var i = (1 + 1);

也就是说,没有。允许使用括号,因为它们在任何表达式中都允许影响评估顺序,但在您的示例中它们只是多余的。

That is, nothing. The parentheses are allowed because they are allowed in any expression to influence evaluation order, but in your examples they're just superfluous.

return 不是函数,而是语句。它在语法上类似于其他简单的控制流语句,如 break continue ,它们也不使用括号。

return is not a function, but a statement. It is syntactically similar to other simple control flow statements like break and continue that don't use parentheses either.

这篇关于return和return()有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆