Introduction to JavaScript (1)

A complete JavaScript implementation should consist of the following three distinct parts: the core (ECMAScript) provides the core language functionality, the Document Object Model (DOM) provides methods and interfaces for accessing and manipulating web content, and the Browser Object Model (BOM) provides and Browser interaction methods and interfaces

DOM is not just for JavaScript, many other languages ​​also implement DOM

The main way to insert JavaScript into HTML pages is to use the <script> element. You can embed JavaScript code directly in the page, or you can include external JavaScript files. The best practice is to use external files as much as possible.

Traditionally, all <script> elements should be placed in the <head> element of the page

The browser will parse the <script> elements in the order in which they appear in the page. When the interpreter parses the <script> elements, the processing of the page will temporarily stop

Content enclosed in <noscript> elements will only be displayed if the browser does not support scripting or if scripting is disabled

 

Identifiers are in camel case to be consistent with built-in function and object naming formats

Use C-style comments

To enable strict mode add "use strict"; at the top

It is recommended not to omit the semicolon at the end of a statement at any time, and it is recommended to always use code blocks within control statements - even if there is only one statement in the code block

It is best not to use keywords and reserved words as identifiers and property names for compatibility with future ECMAScript versions

Variables are loosely typed. Use the var operator to define variables. A variable defined with the var operator will become a local variable in the scope where the variable is defined. Omit the var operator to create a global variable, but this is not recommended.

Five simple data types are Undefined, Null, Number, String and Boolean, and one complex data type is Object, which is essentially composed of a set of unordered name-value pairs

Does not support any mechanism for creating custom types, and all values ​​will end up being one of the 6 above data types, the typeof operator is used to detect the data type of a given variable

The Undefined type has only one value, the special undefined, and executing the typeof operator on uninitialized and undeclared variables will return undefined

The Null type has only one value, that is, the special null. From a logical point of view, the null value represents a null object pointer. When the typeof operator is used to detect the null value, the object will be returned.

The Boolean type has only two literal values ​​true and false. These two values ​​are not the same as numeric values, so true is not necessarily equal to 1, and false is not necessarily equal to 0. All types of values ​​have these two Boolean values. Equivalent value, to convert a value to its corresponding Boolean value, you can call the conversion function Boolean()

The Number type can hold positive zero (+0) and negative zero (-0), the two are considered equal, never test a specific floating-point value, the smallest value that can be represented is stored in Number.MIN_VALUE, the value that can be represented The maximum value is stored in Number.MAX_VALUE, and the out-of-range is converted to -Infinity or Infinity, these two cannot participate in the operation, you can use the isFinite() function to determine whether a value is finite or not

NaN is a special value used to indicate that an operand that is supposed to return a value does not return a value, any operation involving NaN will return NaN, NaN is not equal to any value including NaN itself, isNaN() Function to determine if an argument is "not a number"

The conversion function Number() can be used for any data type, parseInt() and parseFloat() are specially used to convert strings to numbers

String type, the string represented by double quotes is exactly the same as the string represented by single quotes, the length of any string can be obtained by accessing its length property, the string is immutable, the transformation functions toString() and String( ) converts a value to a string

The Object type is a collection of data and functionality. Objects can be created by executing the new operator followed by the name of the object type to be created.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325074930&siteId=291194637