Reading Notes of javascript advanced programming (2) Introduction to javascript and javascript notes
Chapter 3: Basic Concepts
ECMAScript has five simple data types (also known as basic data types): Undefined \ Null \ Boolean \ Number \ String, and a complex data type-Object, an Object is essentially composed of a group of unordered name-value pairs.
Typeof is an operator rather than a function.
Undefined type:This type has only one value, that is, undefined. When using var to declare a variable but not initializing it, the value of this variable is undefined.
Var message;
Var message2 = undefined;
Alert (message); // "undefined"
Alert (message = undefined); // true
Alert (typeof message); // "undefined"
Alert (message = undefined); // true
Alert (age); // Error
Alert (typeof age); // "undefined"
Null type:This type has only one value, that is, null. represents a null object pointer.
Var car = null;
Alert (typeof car); // "object"
If (car! = Null ){
// Perform operations on the car object
}
The undefined value is derived from the null value.
Alert (null = undefined); // true
As long as the variable that is intended to save the object has not actually saved the object, you should explicitly let the object Save the null value.
Number Type:
The first digit of octal is 0, and the first two digits of hexadecimal are 0x.
Scientific Notation: e
The minimum and maximum values that ECMAScript can represent are: Number. MIN_VALUE and Number. MAX_VALUE, out of range, will be Infinity value (Number. POSITIVE_INFINITY) or-Infinity (that is, Number. NEGATIVE_INFINITY ).
NaN (Not a Number)
1. Any operation involving NaNde will return NaN.
2. NaN is not equal to any value, including NaN itself.
Alert (NaN = NaN); // false
After receiving a value, IsNaN () tries to convert the value to a value.
Alert (isNaN (NaN); // true
Alert (isNaN (10); // false
Alert (isNaN ("10"); // false
Alert (isNaN ("blue"); // true
Alert (isNaN (true); // false (can be converted to 1)
IsNaN is also applicable to objects. The valueOf () method of objects is called first. If the value cannot be converted, The toString () method is called Based on the returned value.
Numeric conversion:
Functions that convert non-numeric values into numeric values:
1. Number () is used for any data type and does not parse gossip
Var str;
Var str2 = null;
Var str3 = "hello world ";
Number (str); // NaN
Number (str2); // 0
Number (str3); // NaN
Number (""); // 0
Number ("000011"); // 11
Number (true); // 1
Number ("0xA"); // 10
The operations of the unary plus operator are the same as those of Number.
2. parseInt () is used for the string type (ignore the leading space) and can parse the octal
ParseInt ("1234blue"); // 1234
ParseInt (""); // NaN
ParseInt ("0xa"); // 10
ParseInt (22.5); // 22
ParseInt ("70", 8); // 56 (specify the base number, that is, 8 hexadecimal)
ParseInt ("10", 2); // 2
3. parseFloat () is used for the string type (ignore the leading space), and only 10 hexadecimal is parsed.
ParseFloat ("1234blue"); // 1234
ParseFloat ("0xA"); // 0
ParseFloat ("22.34.5"); // 22.34
ParseFloat ("0908.5"); // 908.5
ParseFloat ("3.125e7"); // 31250000
String type:You can use double quotation marks or single quotation marks.
Except for null and undefined values, there is no toString. However, null and undefined can call String () to return the corresponding String. That is, if the value is null, "null" is returned. If the value is undefined, "undefined" is returned ".
ToString () can be used to input a base parameter, indicating the hexadecimal representation of the output, such:
Var num = 10;
Number. toString (2); // "1010"
To convert a value to a string, you can use the plus sign operator to combine it with an empty string.
With statement:
The with statement is used to set the code scope to a specific object. The purpose is to simplify the work of writing the same object multiple times. See examples ···
However, a large number of with statements may cause performance degradation and difficulty in code debugging. Therefore, we do not recommend using with statements when developing large applications.
Switch statement:
The switch statement uses the full operator to compare values, so no type conversion occurs (for example, the string "10" is not equal to the value 10 ).
Function return value:
Except the return statement, no declaration indicates that the function returns a value. In addition, the return statement does not include any return values. At this time, the function will return undefined after it is stopped.
ECMAScript function parameters: Important
Naming parameters are only convenient, but not necessary. The parser does not verify the name parameters.
Parameters in ECMAScript are represented by an array internally. You can access this parameter array through the arguments object to access each parameter.
Modifying the values in the arguments object will automatically reflect the corresponding naming parameters, but modifying the naming parameters will not change the values of arguments. If no name-worthy parameter is passed, it will be automatically assigned the undefined value.
All parameters in ECMAScript pass values, and parameters cannot be passed through references.
ECMAScript functions cannot be overloaded and can be rewritten.
Clear electronic version of JavaScript advanced programming and JavaScript authoritative guide
Leave an email to you.
Clear electronic version of JavaScript advanced programming and JavaScript authoritative guide
I want to download many books on a website. Download the free haoyang electronic bookstore www.chnxp.com.cn /.