基本结构
<!-- <div onclick="alert('你好,我不认识古天乐')"> 点我触发弹出框</div> -->
<!-- js写在最后 -->
<!-- 第一种使用js的方式 -->
<!-- 写script代码要在script标签里写 -->
<!-- text/javascript 表明文档类型是js-->
<!-- <script type="text/javascript">
// 文档对象的书写方法
// js可以接受双引号和单引号
// dom
/* document.write('欢迎来到js世界') */
// 浏览器的弹出框
// bom
// window可省略
window.alert('欢迎来到js')
</script> -->
<!-- 第二种使用js的方式 -->
<!-- <script src="./12.9.js"></script> -->
<script>
// 先声明变量
// var name;
// 再赋值 从右到左
// name="迪迦";
// alert(name);
// 同时声明变量并赋值
// var age = 18;
// alert(age)
// 生命多个变量
//只有最后的sex被赋值了
// 已经声明但没有被赋值就会默认给个undefined
// var b,age,sex='男';
// console.log(b)
// console.log(age)
// console.log(sex)
// var b='李四',age=18,sex='男';
// console.log(b)
// console.log(age)
// console.log(sex)
// 不声明直接赋值
// uername = '蓝色天空'
// document.write(uesrname)
// 使用let定义的变量是不能被重复声明的
// let uesrname = '阿凡提';
// document.write(uesrname)
</script>
运算符
// var ecmscript5及之前的版本用的 是传统的老的ie浏览器支持的
// let 是ecmscript6支持的,ie10及以上的浏览器支持的
//算术运算符
// +
// let num1=1;
// let num2=2;
// document.write(num1+num2);
// 字符串类型的+是拼接不是相加
// 隐蔽式字符转换,会把数字类型的2转化成字符串类型的2进行拼接
// let str1='1';
// let num1=2;
// document.write(str1+num1);
// let num1=1;
// let num2=2;
// document.write(num1-num2);
// let str1='1';
// let num1=2;
// document.write(str1-num1);
// - 会把字符类型的数字转化成数字类型进行正常计算
// let str1='1';
// let num1=2;
// document.write(str1*num1);
// * 会把字符类型的数字转化成数字类型进行正常计算
// let num1=6;
// let num2=2;
// document.write(num1/num2);
// / 会把字符类型的数字转化成数字类型进行正常计算
// %是取余(数)
// let num1=6;
// let num2=2;
// document.write(num1%num2);
// % 会把字符类型的数字转化成数字类型进行正常计算
// num++ = num=num+1
// let num=1;
// num++;
// document.write(num);
// let num = 1;
// ++写在前面表示先加1再赋值
// let a = ++num;
// 结果是2
// ++写在后面表示先赋值再加1
// let a = num++;
// 结果是1
// num++ = num=num+1
// let num=1;
// num++;
// document.write(num);
// let num = 1;
// ++写在前面表示先-1再赋值
// let a = --num;
// 结果是0
// ++写在后面表示先赋值再-1
// let a = num--;
// 结果是1
// document.write(a);
</script>
数据类型
// let uesrname;
// typeof用来检测变量的类型
// undefined类型
// console.log(typeof uesrname);
// null表示一个空值
// let o=null;
// null也属于一个数据类型
// object对象
// console.log(typeof o);
// 返回的是object
// number数字类型
// let num=90;
// console.log(typeof num);
// boolean类型 true false都是关键字
// let flag=true;
// console.log(typeof flag);
// string 字符串类型,用单引号或双引号括起来的文字
// let str='我爱你中华';
// console.log(typeof str);
// 两个=只比较值,下面是true
// console.log(123=='123');
// 是哪个等号比较类型
// 三个=比较类型,下面是false
// console.log(123==="123");
</script>