JS(一) 基础
输出的两种方式
- 页面输出 document.write("hello world")
- 控制台输出 console.log("hello world")
- 弹出警示框 alert("hello world")
数据类型
- 强数据类型:c c++ java go python(强数据类型需要定义是int float string)
- 弱数据类型:js php(不需要定义)
基本数据类型
- number
- string
- bool
- null
- undefined
引用数据类型
- 对象(object)
- 数组(array)
typeof a 用来检测a的类型
变量的命名规则
- 变量名包含 字母 数字 下划线 $
- 变量名开头必须是 字母 下划线 $
- 链接符 side_bar
- 驼峰式 sideBar SideBar
- nav_bar navBarMenu
js运算规则
- 1 + 2 两个number类型直接相加
- "1" + 2 一个string一个number进行的是字符串的拼接 "12"得到一个string类型
- "hah"-"yes" 打印NAN
- == 值相等 如:"1" == 1
- === 值和属性都相等 1 === 1