2.1 Five basic data types in JavaScript (pending update)

Source: Internet
Author: User
Tags null null

[0]5 type of data:

[0.1] Basic data type:Undefined, Null, Boolean, number, String

[0.1.1] Basic type value refers to simple data segments, 5 basic types are accessed by value, because you can manipulate the actual values saved in the variable

The value of the [0.1.2] base type occupies a fixed amount of space in memory and is stored in the stack memory. Copying a base type value from one variable to another creates a copy of the value.

[0.1.3] Cannot add a property to a value of a base type

[0.2] Reference data type:Object

☆ Focus on understanding and mastering parts:

[0.2.1] Reference type values are those objects that can be composed of multiple values. JS does not allow direct access to the in-memory location, that is, the memory space of the Operation object cannot be accessed directly. When you manipulate an object, you are actually manipulating the object's reference rather than the actual object.

The value of a [0.2.2] reference type is an object, held in heap memory, and a variable containing a value of a reference type actually contains not the object itself, but a pointer to that object. Copying the value of a reference type from one variable to another is actually a pointer, so two variables end up pointing to the same object.

[0.2.3] for values of reference types, you can add properties and methods to them, or you can change and delete their properties and methods

[1] Undefined Not defined

[1.1] The undefined type has only one value, which is undefined

[1.2]var a <=> var a = undefined;

[1.3] For variables that have not been declared, you can only perform one operation, which is to use the TypeOf operator to detect its data type "but will cause errors in strict mode"

[1.4] The scene appears:

[1.4.1] A variable that has not been assigned is declared

[1.4.2] Gets the property that the object does not exist

[1.4.3] Execution result of a function with no return value

[1.4.4] Function parameter not passed in

[1.4.5]void (expression)

[1.5] Type conversion

Boolean (undefined): false

Number (undefined): NaN

String (undefined): ' Undefined '

[2] NULL NULL

[2.1] A null type has only one value, which is null, and a null value represents a null object pointer at a logical angle

[2.2] If the defined variable will be used to hold the object, it is best to initialize the variable to null

[2.3] The undefined value is actually derived from a null value, so undefined = = NULL

[2.4] Scenario: object does not exist

[2.5] Type conversion

Boolean (NULL): False

Number (NULL): 0

String (NULL): ' NULL '

[Note that 1]null is an empty object pointer, while [] is an empty array, {} is an empty object, and the three are not the same

[Note 2]null cannot add a custom attribute

[3] Boolean Boolean value

[3.1] A Boolean type has only two values: True and False

[3.2] The scene appears:

[3.2.1] Conditional statement causes the system to perform a hermit type conversion

[3.2.2] literal or variable definition

[3.3] Type conversion

Number (TRUE): 1 | | Number (false): 0

String (True): ' True ' | | String (False): ' False '

[3.4] Boolean ()

Boolean (undefined): false

Boolean (NULL): False

Boolean (non-empty object includes empty array [] and empty Object {}): True

Boolean (not 0): true | | Boolean (0 and Nan): false

Boolean (non-empty including space string): true | | Boolean ("): false

[Note that]true is not necessarily equal to 1,false nor necessarily equal to 0

[4] Number numbers

[4.1] The number type uses the IEEE754 format to represent integers and floating-point values

[Note] You can convert it to a number with a value of

[4.2] Three literal formats are decimal, octal, hexadecimal

[4.2.1] The first digit of the octal literal must be 0, then the octal number sequence (0-7), 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 number

[4.2.2] octal literal is invalid in strict mode and can cause JS to throw an error

[4.2.3] The first two digits of the hexadecimal literal must be 0x, followed by a sequence of hexadecimal digits, with uppercase letters that can be lowercase

[4.2.4] hexadecimal values in the value out of range, such as the occurrence of g,h, etc. will be error

[4.2.5] In arithmetic calculations, all values in eight hexadecimal and hex are eventually converted to decimal values.

[4.3] The numerical value indicates:

[4.3.1]js can be saved as positive 0 and minus 0, and is considered equal

[4.3.2] Floating point value: The number must contain a decimal point, and must have at least one digit after the decimal.

[4.3.2.1] because the floating-point value needs to save twice times the integer value, so JS will lose no chance to convert the floating-point value to an integer value, if the decimal point is not followed by any number or the floating-point value itself is an integer, this value will be saved as an integer value.

[4.3.2.2] The highest precision for floating-point values is 17 decimal places

[4.3.2.3] for a large or very small number, you can use the scientific notation E to represent the floating-point value to represent

[4.3.2.4] By default, JS converts a floating-point value with 6 or more 0 after the decimal point to a numeric value expressed in E notation

[4.3.2.5] The common problem of floating-point calculations based on IEEE754 values is the rounding error. Example: 0.1+0.2 = = = 0.3 (15 x 0) 4

[The numerical range in 4.3.3]js is Number.min_value (5e-324)--number.max_value (1.7976931348623157e+308)

[4.3.3.1] If the positive range is exceeded, the output Infinity (positive infinity), out of the negative range, output-infinity (negative infinity)

[4.3.3.2]+-infinity cannot participate in numerical calculations

[4.3.3.3] Number.max_value+1! = Infinity, because the computer can save up to 52 digits, not save more than 1000, long ago lost precision, that is, the decimal place is all 0, so the addition of the same

[4.3.3.4] Number.min_value-1! =-infinity, which is the same reason, so the result is-1

[4.3.3.5] can be used isfinite () to determine whether a value is poor, including the implicit type conversion number ()

[4.3.3.6]isfinite (NaN)//false

[4.3.4] NaN is not a numeric type

[4.3.4.1] Nan is not equal to any value, including Nan itself

[4.3.4.2] Any operation that involves Nan will return Nan

[4.3.4.3]isnan () to determine whether the number is Nan, which contains the implicit type conversion numbers ()

[4.4] Numeric conversions: number () can be used for any type, parseint () and parsefloat specifically used to convert a string to a numeric value

[Note 1] Number (), parseint (), parsefloat () can accept a variety of binary numbers, but not for strings with numbers

[Note 2] Number (), parseint (), parsefloat () are 1.2. Will error, but the string is ' 1.2. ' You won't get an error.

[4.4.1] Number ()

Number (TRUE): 1 | | Number (false): 0

Number (various binary digits): The decimal number after the operation, such as 1.0 or 1. or 01 will be 1 output

Number (undefined): NaN

Number (NULL): 0

Number (String):

Number (a decimal and hexadecimal string that contains only numbers): decimal digits after the operation

[note] octal is not recognized in the string and is processed in decimal numbers

Number ("and"): 0

Number (string in other case): NaN

Number (object):

Number ([] and [0] and [-0]): 0

Number ([number]): Numeric after operation

Number ([up] and {} and other objects): NaN

[4.4.2]parseint (): When a string is converted, the space preceding the string is ignored until the first non-whitespace character is found. If the first character is not a numeric character or a minus sign, parseint () returns Nan. If it is, continue parsing until parsing is complete or non-numeric characters are encountered.

[4.4.2.1]parseint () can recognize a variety of binary integers, but in parsing the octal literal string, ECMASCRIPT3 parses the octal, but ECMAScript5 does not have the ability to parse the octet

The [4.4.2.2]parseint () function provides a second parameter that represents how many systems, such as: parseint (' 123 ', 16 or 10, or 2)

[4.4.2.3]parseint (various binary numbers): decimal digits after operation, such as 1.0 or 1. or 01 will be 1 output

[4.4.2.4] because parseint () is specifically used to handle string conversion numbers, so parseint (other types include ')//nan

[4.4.3]parsefloat (): Similar to parseint (), spaces preceding the string are ignored until the first non-whitespace character is found

[4.4.3.1]parsefloat () can only parse a decimal string

[4.4.3.2]parsefloat (various binary numbers): decimal digits after operation, such as 1.0 or 1. or 01 will be 1 output

[5] String: A sequence of characters enclosed in single or double quotation marks, the length of any string can be obtained by accessing the Long property

[5.1] character literal, also known as escape sequence

\ nthe line break

\ t watchmaking

\b Spaces

\ r Enter

\f Paper Feed

\ \ Slash

\ ' Single quotation mark

\ "Double quotation marks

\xnn a character in hexadecimal NN (n is 0-f), as \x41 means ' a '

\UNNNN a hexadecimal nnnn that represents a Unicode character (n is 0-f), such as \u03a3 represents the Greek character ε

[5.2] The string in the ECMAScript is immutable

[5.3] string concatenation requires creating a new string, then populating the new string with two strings that need to be stitched together, and finally destroying the original string. This process occurs in the background and is also the reason for the slow concatenation of strings in some older browsers (IE6), but this inefficiency has been resolved later

[5.4] string conversion

[5.4.1]tostring ()

Null and undefined do not have this method

Boolean, Object, String has this method

Number uses this method to pass cardinality 2, 8, 10, 16, such as var num = 10;num.tostring (2);//1010

However, 10.toString (2) will give an error because the number cannot be followed by an identifier

[5.4.2] String ()

With the ToString () method, use the ToString () method

String (null);//' null '

String (undefined);//' undefined '

[5.4.3] to convert a value to a string, you can use the plus operator to add it to an empty string "

[5.4.4] If the value of an item in the array is null or undefined, the value is represented as an empty string in the results returned by the join (), tolocalestring (), toString (), and valueof () methods

Method Example:

1 var teststring = "Hello";2 var Testboobean = true;3 var testundefined = undefined;4 var testUndefined1;5 var testnull = null;6 var testobject = {a:1};7 var testfunction = function () {return;};8   9 alert (teststring);//"string"Ten alert (Testboobean);//"Boolean" One alert (testundefined);//"Undefined" A alert (testUndefined1);//"Undefined" - alert (TESTUNDEFINED2);//"Undefined" - alert (testnull);//"Object" the alert (testobject);//"Object" -alert (testfunction);//"function"

2.1 Five basic data types in JavaScript (pending update)

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.