问答详情
源自:5-4 有参数的函数

为什么结果会出现16 undefined12 undefined的情况,求解答!

<!DOCTYPE HTML>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>函数传参</title>

<script type="text/JavaScript">

   function add3(x,y,z)                

{

 sum = x+y+z;

 document.write(sum+"<br/>");

}

document.write(add3(5,8,3));

document.write(add3(7,1,4));

</script>

</head>

<body>

</body>

</html>


提问者:慕工程8359979 2017-03-27 00:02

个回答

  • Robert_Langdon
    2017-04-04 17:54:08

    add3(5,8,3)运算完是16,电脑输出16,你又在外面包了个document.write,此时document.write(add3(5,8,3))那就是document.write(16),这什么也不是,只能输出undefined了


  • 慕工程8359979
    2017-03-28 19:25:44

    document.write(document.write(16));

    add3(5,8,3)

    这部分是什么意思呢?

  • 水滴石狮
    2017-03-27 00:51:12

    <!DOCTYPE HTML>

    <html>

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <title>函数传参</title>

    <script type="text/JavaScript">

       function add3(x,y,z)                

    {

     sum = x+y+z;

     document.write(sum+"<br/>");

    }

    document.write(document.write(16));

    add3(5,8,3)

    document.write(document.write(12));

    add3(7,1,4)

    </script>

    </head>

    <body>

    </body>

    </html>