(1) The syntax of JavaScript language is similar to that of C language and Java language.
(2) JavaScript programs are interpreted and executed by the client's browser.
(3) In JavaScript, letters are case-sensitive.
Because JavaScript is interpreted and executed, its syntax is far less strict than that of C language. If there is an error in the program, the browser will ignore the wrong part instead of stopping execution.
The JavaScript program is executed on the client side, and it cannot manipulate the database on the server side, so the webpage containing JavaScript is still a static webpage.
Integer constant:
Starting with 0 is an octal number, such as 065.
Starting with 0x is a hexadecimal number, such as 0x3f4a.
Everything else is decimal, such as 35 and -70.
Floating-point constant:
Such as 12.8, -0.65, 1.2e-7.
Boolean constant:
There are two kinds: real and fake.
String constant:
Such as "OK", "a" and "Welcome".
Note: Strings in JavaScript can be separated by double quotation marks or single quotation marks. If the string contains one quotation mark, it needs to be separated by another quotation mark.
Escape character:
For example, \n stands for line feed, \r stands for carriage return, \t stands for tab, \ "stands for double quotation marks and \' stands for single quotation marks.
They are usually used in strings.
Undefined:
Represents an undefined value. Cannot be used for calculation. If a non-existent variable is referenced, or a variable without an assignment, the value is output.
Empty:
Represents a null value. It cannot be used for calculation, but it can be used to assign values to variables and clear their original values.
Note: JavaScript does not have the amount of characters common in other languages, so you need to use a string instead.
The data types of JavaScript can be divided into two categories: primitive types and reference types. The value of the original type variable is stored in the stack, and the value of the variable can be accessed directly when accessing the variable. Reference type variables are stored in the stack as pointers, and their values are stored separately in the stack and need to be accessed through pointers.
Original type: including undefined, empty, Boolean, number and string.
Undefined Type: this value is undefined, indicating undefined quantity.
Null type: the value is null, which is generally used as a placeholder to indicate an object that does not exist yet.
Boolean type: the value is false or true, which is generally used in conditional expressions.
Digital type: numerical type, which can be calculated numerically.
String type: the value is a string and can be processed.
Reference Type: All objects are reference types. Include Boolean values, numbers, strings, arrays, dates, mathematics, etc.
Where Boolean, Number and String can be original types or reference types.
Variables of reference type provide several properties and methods besides accessing variable values.
The variable declaration in JavaScript is guided by the keyword var, and the type of the variable depends on how it is declared.
Declare a variable of the original type:
Var variable name = value; For example:
var x;
var b = true
var k = 20
Var s = "abc variable X has no specified value, and its default value is undefined, variable B is Boolean, variable K is Number, and variable S is String.
Declare a variable of reference type:
Var variable name = new type name (initial value); For example:
var bb = new Boolean(false);
Var str = new string ("hello");
Var arr = new array ("red", "yellow", "blue"); Variable bb is a boolean object, variable str is a string object, and variable arr is an array object.
JavaScript variables are weakly typed, and the type of a variable mainly depends on its value. You can change its type at any time.
For example:
var I;
i = 20
I = "red";
When declared, the variable I is of undefined type. Integer assignment becomes numeric type, and string assignment becomes string type.
Operators in JavaScript are basically the same as those in C language and have the same priority.
Arithmetic operators:+(addition),-(subtraction), * (multiplication),/(division),% (modulus),++(increase),-(subtraction),-(negative).
Logical operators: (and), || (or),! (no).
Comparison operators: (greater than), = (greater than or equal to), (less than), = (less than or equal to), = = (equal to),! = (not equal to), = = (strictly equal to),! = = (not strictly equal).
Note: "Equality" requires that as long as the evaluation is equal, the values are equal and the type is the same. For example,1= "1"is true and1= "1"is false.
Bitwise operators: (bitwise AND), | (bitwise OR), (bitwise XOR), ~ (bitwise negation), (left shift), (right shift), (zero, right shift).
Assignment operators: = (assignment), op= (operation assignment).
Note: Operators in operation assignment can be arithmetic operators or bit operators. For example, "x+= 10" means "x=x+ 10".
Conditional Operator: Conditional? Expression 1: Expression 2
Note: If the condition is true, the value is the value of the expression 1, otherwise it is the value of the expression 2.
String concatenation operators:+,+=.
For example, the result of "each"+"one" is "everyone".
Note: Linked items can include strings, constants and variables, but not all items must be strings. As long as one of the items is a string, they will be linked by strings.
For example, the result of "ex20b" is "ex20b".
New operator:
Used to create objects. For example, new Array () means generating an array object.
Delete operator:
Used to delete objects.
JavaScript statements use';' Boundary, but you can use it normally without semicolons, but you should get into the habit of writing semicolons.
Expression statement:
x = 1;
x++; Conditional statement: If … Otherwise …
If (x0)
k = " A
other
K = "B Multi-branch statement: switch ... ...
Switch (a)
{
case 1:x = " A "; Break;
Case 2: x = "B breaks;
Case 3: x = "C breaks;
Default value: x = "D
} loop statement: while
White (x5)
{
y+= x;
x++;
} loop statement: do ... during ...
do
{
y+= x;
x++;
} while(X5); Loop statement: for
for(I = 1; I = 10; i++)
{
x+= 2;
} Exit the loop: interrupt and continue.
The break statement can exit the loop statement or the switch statement.
The continue statement can end this loop and start the next loop.
JavaScript statements use';' Boundary, but you can use it normally without semicolons, but you should get into the habit of writing semicolons.
Expression statement:
x = 1;
x++; Conditional statement: If … Otherwise …
If (x0)
k = " A
other
K = "B Multi-branch statement: switch ... ...
Switch (a)
{
case 1:x = " A "; Break;
Case 2: x = "B breaks;
Case 3: x = "C breaks;
Default value: x = "D
} loop statement: while
White (x5)
{
y+= x;
x++;
} loop statement: do ... during ...
do
{
y+= x;
x++;
} while(X5); Loop statement: for
for(I = 1; I = 10; i++)
{
x+= 2;
} Exit the loop: interrupt and continue.
The break statement can exit the loop statement or the switch statement.
The continue statement can end this loop and start the next loop.
Object is the most important data type in JavaScript, and an object can contain several properties and methods.
Attributes are equivalent to variables. Some properties have values at the beginning, through which the parameters of the object can be obtained. Some properties are read-only and can be used as constants. The method of referencing object properties is:
The method of object name and attribute name is equivalent to a function, and you can call the method of object to realize the corresponding operation. The method of referencing an object method is:
Object name. Method name (parameter) Some methods don't need parameters, but you can't omit parentheses when calling.
JavaScript supports custom objects, but we usually use system-provided objects in programming. These objects provide rich properties and methods, which can be directly used in programs.
Objects accessible by JavaScript include: local objects, BOM objects and DOM objects.
Local objects are objects provided by JavaScript language, and they can only be used in JavaScript programs. Include Boolean objects, numeric objects, string objects, array objects, data objects, mathematical objects and the like.
BOM object is an object provided by the browser window, provided by the browser developer, and can be accessed through scripting languages including JavaScript. Include window objects, document objects, navigator objects, screen objects, history objects, location objects, and the like.
DOM object is a cross-platform object and can be used in programs in different languages. DOM objects correspond to tags in the page, and each HTML tag is a DOM object.
Object instance:
An object instance is a concrete individual of an object. An object can have multiple object instances. For example, each String is an instance of a string object. When we visit an object, we are actually visiting an instance of the object.
Instances of local objects are usually generated by the new operator, for example:
Var arr = new array ("red", "yellow", "blue");
Var s = "Hello"; Arr is an instance of an array object, and s is the primitive type of String, but it is also a pseudo object, which can refer to the properties and methods of String objects.
The BOM object corresponds to the browser window, which has been instantiated and can be accessed directly. For example:
Window.alert ("Hello!" );
document . write(" Welcome "); Window is an instance of the window object of the current window, and Document is an instance of the document object of the current window.
DOM objects correspond to HTML tags in a page, and each tag is an instance of a DOM object, which is usually accessed indirectly through a window object or a document object, for example:
var a = document . getelementbyid(" txt "); Document.getElementById("txt ") is used to get the DOM object corresponding to the id="txt" tag in the page.
Note: In JavaScript, object names, property names and method names are case-sensitive. For example, "Mathematics. PI "cannot be written as" math.pi "and" Document.write "cannot be written as" document.write ".
This keyword:
This is a reference to the current object itself, and you can directly call the properties and methods of the current object. For example:
Input type = "radio" name = "RR" value = "a" onclick = "sel (this. value)"/input is an HTML tag, but it is also a DOM object, where this. Value is the value of the value property that refers to this input object.