JavaScript second time Basic learning notes (to be continued ...)

Source: Internet
Author: User

1. XHTML-compatible methods:

<script>//<![ cdata[    ...    ... // ]]></script>

2. Document mode:

IE5.5 introduced, initially contains 2 kinds: promiscuous and standard mode, after IE proposed quasi-standard mode; the document does not begin to declare the document type, and the browser turns on promiscuous mode by default.

3. The noscript tag is used to prompt the browser not to support scripting.

4. Syntax:

4-1, case-sensitive: Everything in ECMAScript is case-sensitive (such as variables, function names, operators ...).

4-2. Identifiers:

The first character must be a letter, underscore, or dollar symbol ($);

The remaining characters can be characters, underscores, dollar symbols, or numbers;

(Note: the letter of an identifier can also contain extended ASCII or Unicode alphabetic characters )

4-3. Note: Single line and multirow (//or/**/).

4-4, Strict mode: ECMAScript5 introduced the concept of strict mode, by adding "usestrict" to the top of the code block to start the strict mode.

4-5, statement: It is divided by a good ending, but can be omitted, then it is determined by the interpreter end of the statement. (Note: personal understanding plus points good is a good programming habit )

5. Variables: ECMAScript variables are loosely typed and can hold any type of data. (use Var to define the declaration variable).

Note: variables defined with VAR will be local variables in their scope ;

variables defined without VAR will be global (but not recommended), but in strict mode this defines the variable as an error (REFERENCEERROR);

6. Data type:

5 basic types (undefined,null,boolean,number,string) and an object (object) type.

You can use TypeOf to initially detect data types.

Object.prototype.toString.call (null);   // [Object Null] typeof null;    // Object

6-1. Undefined type:

There is only one value, that is, undefined, which defines the uninitialized variable as the value.

When you use typeof to detect undefined variables and defined but uninitialized variables , the result is undefined, but using undefined variables results in an error.

6-2. Null Type:

It also has only one value, which is null, and from a logical point of view, the representation of its value is a null pointer (which is exactly why TypeOf detects the object in fact).

The undefined value is actually derived from a null value, so

null);    // true null);    // false

6-3. Boolean type:

It has a value of 2: True and False (case sensitive);

You can use Boolean () to convert other types of data to a Boolean value that corresponds to a relationship such as:

Convert type            to True          converts to Falseboolean          true                 falseString         Any non-empty string null       string      number any non-0 numeric value         0 or Nanobject          any object                 nullUndefined                           Undefined

6-4. Type of Number:

It is represented using the IEEE754 format: decimal, octal (first digit must be zero, invalid in strict mode), hexadecimal (the first 2 bits must be 0x (0));

6-4.1, floating point number:

It can be no integer before the decimal point, but must have after the decimal point;

Its maximum accuracy is 17 decimal places, so its calculation will have rounding errors, such as:

Console.log (0.1+0.2= =0.3);  //

6-4.2, range of values:

Maximum value (number.max_value) and minimum (number.min_value), Positive infinity (Infinity) and negative infinity (-infinity);

You can use the isfinite () function to detect whether a value is poor, and return true to indicate between the minimum and maximum;

6-4.3, NaN:

That is, a non-numeric (not a number) is a special value, and it contains 2 characteristics: Any operation that involves Nan is returned as Nan and is unequal to any (including itself) Console.log (Nan==nan); // false ;

6-4.3, numeric conversions:

There are 3 methods: Number (), parseint (), and parsefloat (); The first one is suitable for any type, followed by 2 conversion string types;

Number 's rule:1, Boolean type:true-1;false-0;2、NULL-0;3, undefinedNaN;4, String type: Contains only numbers (including the sign), converted to decimal number (leading 0 is ignored), valid floating-point format (which ignores leading 0), valid hexadecimal format (such as 0xf), empty string-0; the other is NaN;5, the first valueof of the object, and the ToString if it is Nan;
parseint () and parsefloat () convert the string to a numeric value (ignoring the space in front of the string until the first non-whitespace character is found);
parseint () Differences in parsing of octal literals in ECMASCRIPT3 and 5
var num = parseint ("070"); 3 is considered to be octal, the conversion to decimal is the 56,5 0 (the leading of octal 0 is invalid)
Noteparsefloat () ignores leading 0)
For this parseint () provides a second parameter specifying the cardinality of the transformation.

6-5. String Type:

It consists of 0 or more 16-bit Unicode characters;

It also contains a special character literal, also known as an escape character;

characteristics, it is immutable;

Type conversions: ToString () and string ();

JavaScript second time Basic learning notes (to be continued ...)

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.