1-1 前言
1、js是什么
js 是门语言,我们用来跟浏览器沟通的一门语言,学会了这门语言我们就能和浏览器沟通了,就好像我们学会了英语,我们就能和美国人沟通一样。
2、js 用来干什么, js 在可以在哪里运行
js 可以用来跟浏览器沟通,它的具体工作一般就是:存储数据,传输数据,展示数据js 主要运行在浏览器和其它支持它的平台上
1-2 js的引入
1、内嵌式
<body> <script> alert('我是js') </script> </body></html>
2、外部引入式
<body> <script src="./demo1.js"></script></body>
1-3输出语句
1、什么是语句
js语句用来向浏览器发送命令以分号作为语句结束的记号。一行代码可以有很多条语句为了压缩大小,加载更快,部署上线的时候会把代码压缩成一行。
2、输出到浏览器
- document.write - alert - innerHtml - innerTex
<script> document.write('刘享受'); document.write('<br/>'); document.write('高危'); document.write('<br/>'); document.write('林余生'); // alert(232323); // alert('hello'); // document.getElementById('app').innerHTML = '<div><button>点我啊</button></div>'; // document.getElementById('app2').innerText = '<div><button>点我啊</button</div>';</script>
3、输出到控制台
- console.log() - console.warn() - console.error()
<script> console.log(234234); console.log('hello'); console.log(10+20); console.log('\n'); console.warn('对不起,你xxxx'); // console.error('程序报错了');</script>
1-4 注释
- 注释的作用:对代码进行说明
单行注释: // 或者 /**/多行注释:/*****/