JavaScript reading notes (2)--Data type

Source: Internet
Author: User
Tags number sign

1. Strict mode: A different parsing and execution model is defined in JavaScript. In strict mode, some indeterminate behavior will be handled, and some unsafe operations will throw an error.

Usage is added in the script: "Usestrict";

This is a compilation instruction that tells the engine to switch to strict mode;

2, the statement in JavaScript, if not with a semicolon, by the parser to determine the end of the statement, but it is not recommended to do so;

JavaScript keyword:

Break,case,catch,continue,debugger*,default,delete,do,else,finally,for,function,if,in,instanceof,new,return, Switch,this,throw,try,typeof,var,void,while,with;

JavaScript reserved words:

Abstract,boolean,char,class,const,debugger,double,enum,export,extends,final,float,goto,implements,import,int, Interface,long,native,package,private,protected,public,short,static,super,synchromized,throws,transient, Volatile.

3. JavaScript variables are loosely typed and can be used to hold any type of data;

A variable defined with the var operator becomes a local variable in the scope that defines the variable;

Variables defined without var are global variables, while in functions, global variables defined are difficult to maintain and are not recommended;

4, ECMAScript has 5 types of data (basic data type): undefined,null,boolean,number,string;

There is also a complex data type object, which is composed of a set of unordered name value pairs;

ECMAScript does not support any mechanism for creating custom types;

typeof operator return value: typeof (95) or TypeOf 95

undefined-This value is undefined (when declaring a variable with Var but not initialized, when the variable is not declared )

boolean-Boolean value

string-string

number-value

Object-object or null

function-function

For variables that have not been declared, only one operation-typeof can be performed, and delete does not cause an error, but it has no practical meaning;

5, a null value represents an empty object pointer, you should explicitly let the variable save the null value when the variable that holds the object has not actually saved the object;

Alert (null==undefined); returns True, (undefined value derived from null value)

6. Type of number

(1) Minimum value-number.min_value (Infinity)

Group Large value-number.max_value (-infinity)

Isfinite () function-Determines whether a value is between the minimum and maximum values

(2) NaN (not a number), indicating that an operation that would have returned a numeric value did not return a numeric value

Any operation involving Nan will return a nan;

Nan is not equal to any value, including itself;

The IsNaN () function, any value that cannot be converted to a number will cause the function to return true;

When the isNaN function is called based on an object, the object's ValueOf method is called first, and then the return value of the method can be converted to a value;

(3) numeric conversion

Number () function-available for any type

parseint () function-Applies to strings, mainly to see if they conform to numeric patterns

Ignores the preceding space until the first non-whitespace character is found, parsing to the end of a non-numeric character;

Returns Nan if the first character is not a number sign or a minus sign;

Can parse octal and hexadecimal, you can specify how many binary with the second parameter

Parsefloat () function-parses each character starting from the first character, or encounters an invalid floating-point number

Only the decimal number is parsed;

Ignoring the leading 0;

Returns an integer if the argument can be parsed as being said;

7, string, you can use single quotation marks, you can also use double quotes string is immutable;

Convert to String:

The ToString () method: null and undefined calls to non-callable values can pass a parameter as the cardinality of the output value, which defaults to 10,num.tostring (2);

String () Method: can convert any type of value to a string, if the value has the ToString method, call the method, NULL returns "NULL"; undefined returns "undefined";

8, object type, objects is a set of data and functions;

(1) You can create a custom object by creating an instance of type object and adding a property or method to it;

var o=new Object ();  Equivalent to Var o=new Object; Recommended parentheses

(2) The object type is the basis of all other instances, and any properties and methods that the object type has also exist in more specific objects, with properties and methods:

constructor-Save the function used to create the current object;

hasOwnProperty (PropertyName)-Checks whether a given property exists in the current object;

isPrototypeOf (object)-checks whether the incoming object is a prototype of another object;

propertyIsEnumerable (PropertyName)-Checks whether a given property can be enumerated using the For-in statement;

toLocaleString ()-Returns the string representation of the object, corresponding to the region of the execution environment;

ToString ()-Returns the string representation of the object;

ValueOf ()-Returns the string, numeric, or Boolean representation of the object;

Objects in the ECMAScript do not necessarily apply to other objects in JavaScript, objects in the browser environment, such as objects in the BOM and Dom, belong to the host object and do not necessarily inherit object;

JavaScript reading notes (2)--Data type

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.