Basic syntax for javascript:
I. Order of execution
JavaScript programs are executed line-by-row in the order in which they appear in the HTML document, preferably in an HTML file tag if they need to be executed throughout an HTML document. Some code, such as code in the body of a function, is not executed immediately, but only if the function is called by another program.
Second, case-sensitive
JavaScript is strictly case-sensitive. For example, str and STR are two completely different variables.
Three, semicolons and spaces
In JavaScript, the statement ";" is optional, but it is best to add ";" at the end of each sentence; This is a very important code-writing habit.
In addition, JavaScript ignores extra spaces, so users can add spaces to the script to improve the readability of the code.
There are four ways in which JavaScript is referenced in HTML:
Page Header introduction (inside Head tag);
Page references (inside the body tag);
element in the event of a reference (the tag attribute is referenced);
introduce external JS file; Syntax:
The relationship between JavaScript and Java:
Although the name is similar, but the nature is different;
1. JavaScript is often used in Web pages, while Java can be used in various fields such as Web pages, mobile apps, and software.
2. Java is an object-oriented language, in essence, JavaScript is more like a functional programming language.
JavaScript data structures are: identifiers, constants, variables, keywords;
JavaScript data types can be categorized into two main categories: the underlying data type, and the special data type.
The underlying data types include the following four kinds:
The numeric type (number) is divided into integral and floating-point types (int and float).
The Boolean (Boolean) value is true and false.
A string literal.
There are 3 types of special data:
Null value (NULL);
Undefined value (underfined);
Escape character;
The JavaScript operator can be divided into the following 5 types according to the operator type:
Arithmetic operators
Comparison operators
Assignment operators
logical operators
Conditional operators
typeof () Operator: used to return the data type currently accommodated by his operand, which is particularly useful for determining whether a variable has been defined.
For example: typeof (1); The return value is Number;type ("JavaScript"); The return value is string;
JavaScript Data type conversions:
Convert the string to integer or float with parseint () and parsefloat ();
Convert a numeric type to a string type method of. toString ();
The basics of getting started with JavaScript and how they are referenced in HTML and how they relate to Java