JS Advanced Programming Learning Notes Chapter III Basic concepts (syntax, data types, flow control statements, functions)--Leak checking

Source: Internet
Author: User

First, the syntax:

    1. Case sensitive

2. Identifier: Refers to the name of a variable, function, property, or parameter of a function
A, the rule of the marker: ① The first character must be a letter, an underscore (_), or a dollar sign ($).
② Other characters can be letters, underscores, dollar signs, or numbers.
b, the marker is in hump case format.
C, Strict mode: Add the following code at the top: "Use strict";
D, statement: Add a semicolon at the end, and use code blocks in a control statement as a best practice.


Ii. keywords and reserved words


Variables: ECMAScript variables are loosely typed and can hold any type of data. And when the variable is initialized, the type is not marked for it.
1, it is not recommended to modify the variable to save the worthwhile type, but this operation is valid
2. Variables defined using the var operator are local variables. After the function exits, it is destroyed.
3. It is not recommended to omit the var operator to define global variables. If you deliberately ignore the var operator, it can cause unnecessary confusion because the variable is not immediately defined. Assigning values to undeclared variables in strict mode will cause an error.

Iv. data type: ECMAScript there are 5 simple data types (base data types)--undefined, Null, Boolean, number, and string. A complex data type--object.

1.typeof operator--detects the data type of a given variable

undefined--If this value is undefined;
boolean--If this value is a Boolean value;
string--If this value is a string;
number--If the value is numeric;
object--If the value is an object or null;
function--If this value is a function;

2.undefined Type:
A, when declaring a variable with VAR but not initializing it, the value of this variable is undefined. (obtained by default).
b, for variables that have not been declared, you can only perform one operation and use the TypeOf operator to detect its data type. Returns undefined.
C, initialize the variable as explicitly as possible, so that when ytpeof returns undefined, we know that the variable being detected has not been declared, not yet initialized.

3. Null Type:
A, if the defined variable is intended to be used in the future to hold the object, it is better to initialize the variable to null instead of the other value.
b, the value of undefined is derived from null, so their equality test returns TRUE. (Double-equal returns True, and third-equal returns false).

4. Boolen Type:
A, Boolean literal true, and false are case-sensitive. The other notation is not a Boolean value, but a marker.
All types of values in B, ECMAScript have values that are equivalent to these two Boolean values. To convert a value to a corresponding Boolean value, you can call the Transform function Boolean ().

Data type The value converted to true Value converted to False
Boolean True False
String Any non-empty string Empty string
Number Any non-0 value (including infinity) 0 and Infinity
Object Any object Null
Undefined Not applicable Undefined

5. Type of number:
The first digit of a, octal literal must be 0 (0), followed by an octal sequence. If the value in the literal value is out of range, then the leading 0 is ignored and the subsequent value is parsed as a decimal value. Octal literals are not valid in strict mode.
B, the first two digits of the hexadecimal literal must be 0x, followed by any hexadecimal digits 0~9 and a~z, and the letters can be uppercase and lowercase.
C, in the arithmetic calculation, all octal and 16 binary representation of the number is eventually converted to decimal
D, floating-point values:
The ① value must contain a decimal point and must have at least one digit after the decimal point. There can be no integers before the decimal point, but not recommended. If a floating-point value can be converted to an integer value, it is converted.
The ② maximum minimum value is expressed in e notation.
③ the accuracy of floating point numbers is a bug, so do not test the value of a floating-point number
E, value Range: Values beyond the JS value range are automatically converted to infinity. Infinity cannot participate in the calculation. The Isfinite () function returns True when the parameter is between the maximum and minimum values.
F, NaN: Used to indicate that an operand that would have returned a number did not return a numeric value.
① any operation involving Nan, it returns Nan. Nan is not equal to any value, including himself.
The ②isnan () function receives a parameter that can be of any type, and the function attempts to convert the argument to a numeric value, and any values that cannot be converted to a number will cause the function to return true. This function applies to the object, calling the object's valueof () method first, and then determining whether the value returned by the method can be converted to a number. If not, then the ToString () method is called based on this return value, and the return value is tested.
G, numeric conversions:
①number (): For any data type
If it is a Boolean value, True and False return 1 and 0, respectively.
If it is a numeric value, simply pass in the return.
If NULL, 0 is returned.
If it is undefined, return nan.
If it is a string:
If the string contains only numbers (either positive or negative), it is converted to decimal, ignoring leading zeros.
If the string contains a valid floating-point format, it is converted to the corresponding floating-point format, ignoring leading zeros.
If the string contains a valid 16 binary, it is converted to a decimal integer value of the same size.
If the string is empty, it is converted to 0.
If the string contains characters other than the above format, it is converted to Nan.
If object: Call the ValueOf () method, and then convert the return value according to the previous rule. If the result of the conversion is Nan, the ToString () method is called and then converted again according to the previous rule.



JS Advanced Programming Learning Notes Chapter III Basic concepts (syntax, data types, flow control statements, functions)--Leak checking

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.