1. Javascript syntax
A. Javascript variable names, functions, and operators are case sensitive.
B. variables are of a weak type. ecmascript is not similar to Java and C ++. Variables in ecmascript do not have specific types. Use VaR to define variables.
C. ";" at the end of each line may or may not
D. The javascript annotation is "/* js content */"
2. Javascript Variables
A. the variables defined in javascept are var test = "Hello JS" (VaR is short for variable .) The initial value of the test variable is "Hello JS"
B. variables defined in ecmajavascipcan be not initialized. For example, VAR test;
C. The variables of javascipt are of weak type, so they can store different types of values. For example, VAR test = "Hello JS"; test = 123; this is acceptable.
D. variable name rules: the first character must contain letters, underscores, or hyphens ($)
E. Naming rules for variable names
Camel markup-lowercase letters, followed by uppercase letters
For example, VAR mytestvalue; var myresult;
Pascal markup-the first letter is in upper case, and the subsequent words start with an upper letter.
For example, VAR mytestvalue; var myresult;
Hungary markup-Add a lowercase letter before the variable based on Pascal notation to indicate the type of the variable.
For example, VAR imytestvalue = 55; var smyresult = "Hello JS ";
3. Original Value, reference value
A. Original Value
Primitive values are simple data segments stored in stacks, that is, their values are directly stored in variable access locations.
B. Reference Value
The reference value is the object stored in the heap (herp), that is, the value of the storage variable is a pointer (point) pointing to the object's memory
The original ecmascript types include undefined, null, Boolean, and string.
4. Several important primitive types
A. undefined type
This type has only one value: undefined. When the declared variable is not initialized, the value of this variable is undefined.
That is, VAR test; alert (TEST); outputs undefined.
Note: The undefined value is not the same as the undefined value. However, the typeof operator does not really distinguish the two values. Please pay attention to the following:Code:
VaR otemp;
Alert (typeof otemp); output "undefined ";
Alert (typeof otemp2);/* otemp2 is not defined anywhere */output "undefined ";
However, you cannot use alert (otemp2 = undefined) without defining variables. // This produces an error: the variable is undefined.
If the function does not explicitly return a value, the default return value of this function is undefined.
B. null type
The null type also has only one dedicated value null. The undefined value is actually derived from null. Therefore:
Alert (null = undefined); // outputs true
Although the two values are equal, their meanings are different. Undefined indicates the value of a variable that is declared but not granted to it during initialization. null indicates
Objects that have not been saved. If the return value of a function is an object, null is usually returned when the object cannot be found.
C and Boolean types
Boolean has two values: true and false.
During type conversion: Null String = false; number 0 = false; non-zero number and non-empty string = true;
By default, false is returned for "null = true/false", and false is returned for "undefined = true/false ".
VaR ofalseobject = new Boolean (false );
VaR result = ofalseobject & True; // The final result here is true, because the and operation will automatically convert the ofalseobject object
Is true, rather than the value of this object. Therefore, the returned value is true;
During forced type conversion: var B = new Boolean (null); then the final result of B is false; var B = new Boolean (undefined );
5. Functions
A function is a set of statements that can be run anytime, anywhere. It consists of a keyword function, a set of parameters, and Code placed in parentheses.
If the function does not use the return statement or an empty Return Statement, the return value of this function is undefined.
Functions in ecmascript cannot be overloaded. If two functions in the same region use the same name, no error is thrown.The second function is actually used during execution.
Arguments object: special objects can be used in substitute function code. developers can access them without explicitly specifying this parameter name. ArgumentsIs the list of all parameters of the function.