JavaScript Study Notes: Variables
I'm starting to learn JavaScript; these are my notes. Some parts may be incorrect, please excuse me. Writing them down mainly to help me review later.
New Syntax:
prompt pops up a fill-in dialog where you can enter content information.
alert pops up an alert box, displaying information to the user
console.log: console log (console is the console, log is the log)
Variables
Essence: A variable is a container for storing data.
Variable names: When there are too many variables to find, you need to name the variables.
Using variables:
- Declaration: var myname
- Assignment: myname = 10
- Variable initialization: var myname = 'Xiao Yuan'; Writing a sequence of variables together is called initialization of variables.
At this time console.log(myname) can output the value of the variable myname.
Case:
anli1.png
(1) A prompt pops up to enter information, and the information is assigned to the variable myname
(2) An alert pops up; its content uses the data of myname
(3) The console outputs the value of myname.
Variable Syntax (Update-related)
Meaning: When a variable has new data, it replaces the old data. The last assignment takes precedence.
How to declare multiple variables

bl.png
Special cases of variables
1: Only declare, do not assign. The output is undefined (the browser doesn't know exactly what value it is.)
2: Do not declare, do not assign; output to the console. The result is an error.
3: Only assign, not declare; the console can display it, but it's not recommended.
bl3.png
Naming conventions for variables
1: Letters, digits, and underscores. (num01, _num, usrName)
2: Cannot start with a digit, for example (var 18age) will throw an error.
3: Cannot use keywords as variable names, for example (var var)
4: Variable names should be meaningful. Youdao Translation
5: CamelCase naming. The first letter is lowercase, the first letter of the following words is uppercase. (myFirstName)
6: Case is strictly case-sensitive.
Small logic case (Green Apple and Red Apple swap positions)

bl4.png