Var
Declares a variable, optionally initializing it to a value
Let
Declares a local variable of a block scope, optionally initializing it to a value
Const
Declares a read-only constant
Variable
A JS identifier must start with a letter, underscore, or dollar sign, and subsequent characters can be numbers,
And the JS language is case-sensitive
declaring variables
1. Use the keyword var. For example, Var a=1, this syntax can be used to declare local variables and global variables
2. Assign values directly. For example, X=1. This will declare a global variable and produce a in strict mode
The Referenceerror reference error indicates that a non-existent variable is referenced. You should not use this method when declaring variables
3. Use the keyword let. For example let y=2. This syntax can be used to declare local variables of a block scope
Variable evaluation
For variables declared with VAR or let and unassigned, the value is set to undifined.
Attempting to access an undeclared variable or accessing an uninitialized variable that uses a let declaration causes a referenceerror
Exception is thrown
You can use undefined to determine whether a variable has been assigned a value
var x;if (x===undefined) {dothis ();} Else{dothat ();}
Undefined value equals false of Boolean value
var x;if (!x) {myFunction ();}
Undefined values in a numeric environment are converted to Nan
var x;a+2//nan
Null value NULL is treated as a null in a numeric type environment and is treated as false in a Boolean type environment.
var n=null;typeof (n); Object
Scope of the variable
Variables declared outside of all functions are called global variables
JavaScript syntax and types