JavaScript Basics 1

Source: Internet
Author: User
Tags value store

JavaScript reference issues

1:<script> tags are referenced in embedded HTML pages, and the corresponding file URLs must be set with the SRC attribute when the external reference is a JavaScript file. 2: Defer and async,<script> elements are parsed in the order in which they appear in the page, with the label position behind the main content:. </body> Front. The 3:defer property allows the script to execute after the document is fully rendered, and the deferred script is always executed in the order in which they are pointing. The 4:anync property can indicate that the current script is no more than waiting for other scripts, does not have to block document rendering, and does not guarantee that asynchronous scripts execute in the order in which they appear. 5:<noscript> Specifies the alternate content that is displayed in browsers that do not support scripting, but starts the script without displaying any <noscript> content.

Basic concepts

Grammar

Everything in ECMASCRIPTB (variables, function names, and operators) are case-sensitive. identifiers (variables, functions, attributes) or function arguments. Identifier formatting rules: 1, the first character must be a letter, underscore (_), or dollar sign ($), the hump is the best.

Single-line comment//Multiline comment/* */

Strict mode: Resolve the indeterminate behavior, unsafe throws an error, add "use strict" at the top, can also be written in the method.

Statement: Ends with a semicolon, you can omit the semicolon, and the parser determines the end of the statement but does not agree. A conditional control statement, such as an if statement, requires a block of code that uses code blocks in a control statement to make the encoding intent clear and to reduce the chance of code errors.

Keywords and reserved words : A keyword can be used to control the start or end of a statement. Keywords are reserved for speech and cannot be used as identifiers, such as break if do, and so on. Reserved words are: int short, and so on.

Variable

Variables are loosely typed data, which can store any type of data, define variables with the var operator (Note that var is a keyword), and the latter variable is an identifier.

When Var defines a variable in a function function, the variable is destroyed after it exits, and if a variable is defined inside a function and the Var is removed, then the variable becomes a global variable and is accessed outside the function of the file.

Data type

Five basic data types: Undefined,null,boolen,number and string. A complex data type object.

First of all, typeof, which detects the data type of a given variable, typeof null returns an object because it is an empty, Chrome7 previous version, typeof regular expression, returns function, and the other returns object, From a technical point of view, a function is an object in ECMAScript, not a data type, and a function is a special property, so the functions and other objects are distinguished by the TypeOf operator.

One, underfind (undefined)

There are two cases of underfind, 1 is undeclared, 2 uninitialized (that is, no assignment).

Two, null (null pointer object)

When you save an object, you are not empty, and if you save a variable instead of a real object, you save it as null. (The equality operator (= =) between UNLL and Underfind returns a value of true. They can be converted).

Three, number (numeric)

There are two types of integer and floating-point values.

Integer, except 10, octal: the first digit of the literal is zero, and then the octal sequence is 0-7. Decimal: The front two bits must be 0x, followed by any 16 decimal digits, (0-9 and A-f) a-f can be uppercase or lowercase. However, all octal and decimal numbers are converted to decimal values at the time of calculation.

Floating-point numeric value, which must include a decimal point, must have a valid number after the decimal. Twice times the number of integers in a floating-point value store, so the floating-point value uses e notation, which is the science notation,

For example, 0.00000000000000003 is a simple 3e-17, the default of 6 more than 0 in e notation.

numeric conversions

Number (), parseint () and parsefloat () these three functions convert non-numeric values to numeric values, the first numbers () are used for conversions of any data type, while the other two are dedicated to converting strings to numeric values.

Number () function conversion rule:

1, if the Boolean value, True and false will be converted to 1 and 0 respectively;

2, if it is a numeric value, simply pass in and return.

3, if NULL will return 0;

4, if Undfind, will return nan;

5, if it is a string. As follows

* If the string is a number, convert it to a string.

*, if it is a valid floating-point value, it will be converted to the corresponding floating-point value.

The *,16 binary is converted to decimal.

*, NULL conversion to 0.

*, the above thought converted into Nan.

6, if it is an object, call the ValueOf () method, in accordance with the preceding rule transformation. If the conversion result is Nan, the ToString () method is called, and the return string is converted in accordance with the preceding rule.

The parseint () method determines whether a number pattern is true, and when the string is converted, he ignores the spaces in front of the string until a non-null value is found, and if the first character is not a numeric value or a minus sign, Nan is returned.

parseint () Returns a value of Nan,number for an empty string of 0.

If the string first is a numeric character, it will continue to parse until it finishes parsing so the numeric character, or the non-numeric character, is encountered.

If octal and hexadecimal are automatically parsed into decimal. others as above.

The Parsefloat () method is the same as above, but when he encounters the first decimal point it is valid and is invalid.

Boolean (Boolean type)

String (String)

Object (Objects)

JavaScript Basics 1

Related Article

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.