current position:Home>Front end - JS based variables
Front end - JS based variables
2022-01-26 22:15:04 【Dunhuang Bi painting】
Declare variable keywords
Variables are used to store data
You need to declare variables first , Can be used
There are three main keywords used to declare variables :let、const、var
var The key words are the old version (ES5)JS Used by the , Now it's out
let
let Is the keyword used to declare variables in the new version ,let The declared variables are ordinary variables
usage :
let a = 1
// perhaps
let a
a = 1
The above uses let
Declare a variable , A variable called a
, The value is 1
Use of variables
Proper use :
// Declare variables first 【 This is an annotation. 】
let a = 1 // Assign values when declaring
// Use variables after
alert(a) // The browser will pop up here :1
The above code can also
let a // let Variables can be declared without assignment
a = 1 // The variable a Assign a value
alert(a) // Popup :1
Incorrect usage :
// Use variables here first
alert(a) // An error will be reported here
// Make a statement after , Wrong usage , Because in use , Variable is not declared , So there's an error
let a = 1
Conclusion :
Variables must be declared before using !!!
First use , An error will be reported after the statement
Declaration of variables
In the same environment ( Within the same scope ) All variable names cannot conflict , Otherwise, the report will be wrong
let a = 1
// Here are other codes
let a = 1 // An error will be reported here
Conclusion :
Variables cannot be declared repeatedly within the same scope
The concept of scope will be explained in the following chapters
Change the variable value
let The value of the declared variable can be changed
let a = 1
alert(a) // Pop up here :1
a = 2 // The variable... Has been changed here a The value of is 2, Use later a when , The value is a
alert(a) // Pop up here :2
Conclusion :
When changing the value of a declared variable , Just assign a value to the variable directly , There is no need to write a declaration keyword
const
const
The declared variable is Constant , Instead of Common variables
Constant : A constant is a special variable , The value of this variable must be set at the time of declaration , And cannot be changed later .
const a = 1 // declare constant a, The value is 1
a = 2 // Modifying the value of constant here is an illegal operation , So there's an error
besides ,const
The properties of constants are similar to let
Variable consistency .
Keyword reserved word list
abstract | arguments | boolean | break | byte |
---|---|---|---|---|
case | catch | char | class* | const |
continue | debugger | default | delete | do |
double | else | enum* | eval | export* |
extends* | false | final | finally | float |
for | function | goto | if | implements |
import* | in | instanceof | int | interface |
let | long | native | new | null |
package | private | protected | public | return |
short | static | super* | switch | synchronized |
this | throw | throws | transient | true |
try | typeof | var | void | volatile |
while | with | yield |
Object and method
Array | Date | eval | function | hasOwnProperty |
---|---|---|---|---|
Infinity | isFinite | isNaN | isPrototypeOf | length |
Math | NaN | name | Number | Object |
prototype | String | toString | undefined | valueOf |
window Keyword under object
alert | all | anchor | anchors | area |
---|---|---|---|---|
assign | blur | button | checkbox | clearInterval |
clearTimeout | clientInformation | close | closed | confirm |
constructor | crypto | decodeURI | decodeURIComponent | defaultStatus |
document | element | elements | embed | embeds |
encodeURI | encodeURIComponent | escape | event | fileUpload |
focus | form | forms | frame | innerHeight |
innerWidth | layer | layers | link | location |
mimeTypes | navigate | navigator | frames | frameRate |
hidden | history | image | images | offscreenBuffering |
open | opener | option | outerHeight | outerWidth |
packages | pageXOffset | pageYOffset | parent | parseFloat |
parseInt | password | pkcs11 | plugin | prompt |
propertyIsEnum | radio | reset | screenX | screenY |
scroll | secure | select | self | setInterval |
setTimeout | status | submit | taint | text |
textarea | top | unescape | untaint | window |
It should be noted that name
This word , Not a keyword or reserved word , In most browsers and situations, it can be used as a variable , However, there may be very few and special cases of abnormality
| textarea | top | unescape | untaint | window |
It should be noted that name
This word , Not a keyword or reserved word , In most browsers and situations, it can be used as a variable , However, there may be very few and special cases of abnormality
copyright notice
author[Dunhuang Bi painting],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201262215009076.html
The sidebar is recommended
- Spring IOC container loading process
- [thinking] the difference between singleton mode and static method - object-oriented programming
- Hadoop environment setup (MySQL environment configuration)
- 10 minutes, using node JS creates a real-time early warning system for bad weather!
- Git tool
- Force deduction algorithm - 92 Reverse linked list II
- What is the sub problem of dynamic programming?
- C / C + +: static keyword summary
- Idea does not have the artifacts option when configuring Tomcat
- Anaconda can't open it
guess what you like
-
I don't know how to start this
-
Matlab simulation of transportation optimization algorithm based on PSO
-
MySQL slow log optimization
-
[Vue] as the window is stretched (larger, smaller, wider and higher), the text will not be displayed
-
Popular Linux distributions for embedded computing
-
Suzhou computer research
-
After installing SSL Certificate in Windows + tomcat, the domain name request is not successful. Please answer!!
-
Implementation time output and greetings of jQuery instance
-
The 72 year old uncle became popular. Wu Jing and Guo fan made his story into a film, which made countless dreamers blush
-
How to save computer research
Random recommended
- Springboot implements excel import and export, which is easy to use, and poi can be thrown away
- The final examination subjects of a class are mathematical programming, and the scores are sorted and output from high to low
- Two pronged approach, Tsinghua Professor Pro code JDK and hotspot source code notes, one-time learning to understand
- C + + recursive knapsack problem
- The use of GIT and GitHub and the latest git tutorial are easy to understand -- Video notes of crazy God speaking
- PostgreSQL statement query
- Ignition database test
- Context didn't understand why he got a high salary?, Nginxfair principle
- Bootstrap switch switch control user's guide, springcloud actual combat video
- A list that contains only strings. What other search methods can be used except sequential search
- [matlab path planning] multi ant colony algorithm grid map path planning [including GUI source code 650]
- [matlab path planning] improved genetic algorithm grid map path planning [including source code phase 525]
- Iinternet network path management system
- Appium settings app is not running after 5000ms
- Reactnative foundation - 07 (background image, status bar, statusbar)
- Reactnative foundation - 04 (custom rpx)
- If you want an embedded database (H2, hsql or Derby), please put it on the classpath
- When using stm32g070 Hal library, if you want to write to flash, you must perform an erase. If you don't let it, you can't write continuously.
- Linux checks where the software is installed and what files are installed
- SQL statement fuzzy query and time interval filtering
- 69. Sqrt (x) (c + + problem solving version with vs runnable source program)
- Fresh students are about to graduate. Do you choose Java development or big data?
- Java project: OA management system (java + SSM + bootstrap + MySQL + JSP)
- Titanic passenger survival prediction
- Vectorization of deep learning formula
- Configuration and use of private image warehouse of microservice architect docker
- Relearn JavaScript events
- For someone, delete return 1 and return 0
- How does Java dynamically obtain what type of data is passed? It is used to judge whether the data is the same, dynamic data type
- How does the database cow optimize SQL?
- [data structure] chain structure of binary tree (pre order traversal) (middle order traversal) (post order traversal) (sequence traversal)
- Webpack packaging optimization solution
- 5. Operation element
- Detailed explanation of red and black trees
- redhat7. 9 install database 19C
- Blue Bridge Cup notes: (the given elements are not repeated) complete arrangement (arrangement cannot be repeated, arrangement can be repeated)
- Detailed explanation of springboot default package scanning mechanism and @ componentscan specified scanning path
- How to solve the run-time exception of test times
- Detailed explanation of k8s management tool kubectl
- Android system view memory command