- 3个输出语句
浏览器窗口输出
alert("Hello word")
控制台输出
console.log("hello");
页面输出
document.write("hello")
- js编写位置
标签的onclick属性中
<button onclick="alert('helloword')">按钮</button>
超链接的href属性中
<a href="javascript:;">超链接</a> 点击不跳转
<a href="javascript:alert('点击');">超链接</a>
- js执行顺序 js是从上到下按顺序执行的
字面量和变量
字面量:
- 不可改变
- 直接使用
变量
- 保存字面量,可以改变
类型 值 变量
类型
java数据类型:
- 原始类型:String、Number、Boolean、Null、Undefined
- 对象类型:Object(对象) 检查变量类型 typeof
console.log(typeof a);
String 字符串
Number 数值
1. 基础知识
- 包括整数和浮点数
- 数字的最大值/最小值 Number.MAXVALUE/Min_MINVALUE
- Infinity 正无穷 -Infinity负无穷
- NaN 不是数字
2. 运算
- 整数可以保证精确
- 浮点数运算,可能不精确
Boolean 布尔值
- true
- false
null和undfined
- Null的值只有一,就是null,专门用来保存空对象typeof会返回object
- Undefined值只有一个,就是undefined。(声明变,但未赋值)