版权声明:转载请注明出处 https://blog.csdn.net/nk1212582/article/details/81321202

背景

由于JS程序不能像C++、Python程序等单独运行,不利于测试一段代码的功能

目的

简单测试一小段JS代码

步骤

(1)新建一个test.html文件

(2)在test.html文件中书写以下内容
<!doctype html> <html> <head> <meta charset="utf-8"> <title>test</title>
<script type="text/javascript"> </script> </head> <body> </body> </html>
(3)在test.html中编写需要测试的JS代码,如下
<!doctype html> <html> <head> <meta charset="utf-8"> <title>test</title>
<script type="text/javascript"> function Student(name, age){ this.name = name;
this.age = age; this.description = function(){ return this.name + "的年龄是:" +
this.age; } } var p4 = new Student("Tony", 28); var p5 = new Student("Tom",
40); console.log(p4.description()) //输出为:Tony的年龄是:28
console.log(p5.description()) //输出为:Tom的年龄是:40 </script> </head> <body> </body>
</html>
(4)再用浏览器打开test.html,按F12,查看console.log()打印输出的内容

友情链接
ioDraw流程图
API参考文档
OK工具箱
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:637538335
关注微信