首页 > 其他 > 详细

函数的返回值return

时间:2019-12-06 19:55:24      阅读:80      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>函数的返回值return</title>
    <!-- 
        return:函数在执行到return;时会结束执行
        如果return后面有返回值,那么函数读到它时,会停止执行,并返回指定的值。
        如果return后面没有返回值,那么函数会在执行完return语句后停止并立刻退出。
     -->
</head>
<body>
    <script>
        function x(){
            return;//无返回值
        }
        document.write(x()+"<hr />");//undefined
        /* ……………………………………………………………………………………………………………… */
        function y(){
            return 1;//返回值:1
        }
        document.write(y()+"<hr />");//1
        /* ………………………………………………………………………………………………………………… */
        function j(a,b){
            if (a>b) return;//如果a>b,结束当前代码
            return a+b;//否则执行a+b
        }
        document.write(j(2,3));//5
    </script>
</body>
</html>

 

函数的返回值return

原文:https://www.cnblogs.com/vinson-blog/p/11997049.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!