新手上路之 js undefined问题

来源:互联网 发布:java经典书籍 编辑:程序博客网 时间:2024/06/07 20:45





</head><body>    <!--1)当声明了一个变量而没有初始化时,这个变量的值就是undefined。        2)调用函数时,该函数有形参,但未提供实参,则该参数为undefined。        3)函数没有返回值时,默认返回 undefined。    -->    <script type="text/javascript">        //1)当声明了一个变量而没有初始化时,这个变量的值就是undefined        var x;        console.log(x);//undefined        //2)调用函数时,该函数有形参,但未提供实参,则该参数为undefined。        console.log('------------------');        function test(a){            console.log(a);        }        test();//调用函数        console.log('------------------');        //3)函数没有返回值时,默认返回 undefined。        var result=test(20);        console.log("result="+result);    </script></body>