函数的返回值return

<!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>
原文地址:https://www.cnblogs.com/vinson-blog/p/11997049.html