JavaScript Overview
JavaScript is an object- and event-driven scripting language, mainly used on the client side.
Features:
1. Interactivity (all it can do is dynamic interaction of information)
2. Security (direct access to the local hard disk is not allowed)
3. Cross-platform (any browser that can interpret JS can execute it, regardless of the platform)
JavaScript is different from Java
1. JS is a product of Netscape. Formerly LiveScript; Java is a product of Sun and now a product of Oracle.
2. JS is object-based, and Java is object-oriented.
3. JS only needs to be interpreted before it can be executed. Java needs to be compiled into a bytecode file first and then executed.
4. JS is weakly typed, and Java is strongly typed.
JavaScript Grammar
Each language has its own grammar rules. JS grammar is very similar to Java, so it is easier to learn. JS also has variables, statements, functions, arrays and other common language elements.
1. Variables
are defined through the keyword var. Weak types do not require specifying a specific data type.
Example: var x = 3; (undefined).
Note: Javascript statements do not need to end with a semicolon at the end, which is a non-strict language feature.
But in order to comply with programming standards, the terminator needs to be defined like java.
And in some cases, a semicolon must be written, such as: var x = 3; var y =5. If two statements are written on the same line, they need to be separated by a semicolon.
1) Keywords: almost the same as Java
2) Identifiers, delimiters: the same as Java
3) Comments: These two types of Java are used : // and /* */
4) Data type: number type, string type, boolean type, undefined (when the variable is declared but not assigned a value)
5) Variable: var (weak Type, similar to Object in Java)
6) In js, single quotes and double quotes are the same, and they encapsulate strings (but there are two quotes at the same time to encapsulate, and the internal ones must be used Single quotes)
7) Global variables and local variables
Global variables----As long as they are not declared inside the function, they are. And it will not be distinguished by curly brackets, nor will it be distinguished by