定义:函数的执行结果
<script>/* 函数的返回值函数的执行结果tips:1、函数调用之后,return后面的语句不会执行2、函数遇到return语句会立即停止,退出3、return语句的作用,将函数内容的值返回给外部*/function go(){return 10;console.log("hello world")}var res = go();console.log(res)</script>
函数return之后,return后面的语句就不会执行了
作用:将函数内部的值返回外部
function go(){
return "hello world";
console.log("good"); // 不会执行
}
console.log(go()); // hello world
如果输出语句只有一段return,可以省略return
<script>
var go=(a)=>{
return a;
}
var show=a=>a;
console.log(show(10))
</script>
<script>
function show(callback){
var b = 20;
callback(b);
}
show(res=>{
console.log(res)
})
</script>
