开始之前
如果你从来没有接触过JS。去下面这个网站 5 分钟感受一下:
入门案例
基于浏览器
JS 通常是和 HTML,CSS 结合使用的。
- 编写 hellojs.html
使用记事本新建一个 hellojs.html
,内容如下:
<!DOCTYPE html>
<html>
<body>
<script>
alert("hello js");
</script>
</body>
</html>
- 效果查看
使用浏览器直接打开此文件。
应该可以看到浏览器直接弹框,内容是 “hello js”。
基于 Node.js
对于 js 的语法讲解,和 html 放在一起讲解,总觉得比较别扭。
就是用 Node.js 进行代码演示。
Node.js 安装 & 使用
自行百度。
或者参考:
扫描二维码关注公众号,回复: 59146 查看本文章
- 编写
js-01-hello.js
任意编辑器编写,内容如下:
console.log("hello js");
- 运行
$ node js-01-hello.js
hello js