变量
例:var age="18"
var 用来声明变量的关键字
age 变量名(自定)一个变量名只能储存一个变量
= 不是等号,为赋值号
18 变量
变量名命名规范
1.以字母 下标符号_ $开头
2.长度不能超过255个字符
3.名字中不能有空格,首字母不能是数字
4.不能使用关键字和保留字
关键字
关键字是在JavaScript已经被规定为具有特殊功能的字。这些关键字可用于表示控制语句的开始或结束,或者用于执行特定操作等。按照规则,关键字也是语言保留的,不能用作标识符。ES2015新增let和const等为关键字。
break | do | instanceof | typeof |
case | else | new | var |
catch | finally | return | void |
continue | for | switch | while |
debugger* | function | this | with |
default | if | throw | delete |
in | try | let | const |
ECMA-262 还描述了另外一组不能用作标识符的保留字。尽管保留字在这门语言中还没有任何特定的用途。但它们有可能在将来被用作关键字。以下是ECMA-262 第3 版定义的全部保留字:
abstract | enum | int | short |
boolean | export | interface | static |
byte | extends | long | super |
char | final | native | synchronized |
class | float | package | throws |
const | goto | private | transient |
debugger | implements | protected | volatile |
double | import | public |
5.严格区分大小写
6.汉字可以使用(但不建议)
定义时常见error
1.undefined /is not defined
创建了变量,没有赋值
2. 变量名 is not defined
变量声明提升
console.log(a);
var a = 20;
正常逐行读取:
实际读取:
声明会提升,实际执行代码
var a
console.log(s)
var a =20
视频教程:
链接:https://pan.baidu.com/s/1o1YcE-I6n6zUpJ3DDvvmCA
提取码:4lsq