JavaScript data types

Source: Internet
Author: User
Tags decode all mathematical functions

#JavaScript数据类型
# #一, raw data type
There are altogether 5 primitive types of javascript: Undefined, Null, Boolean, number, String.

*typeof operator: Determine what the original type of argument is followed by

E.g.typeof true--Returns a Boolean

Note: TypeOf null--returns object because NULL is a placeholder for an object that does not already exist, that is, it knows what the object is looking for, but the object is not found.

1.Undefined type

* This type has only one value: undefined.
* The declared variable is uninitialized, the default value of the variable is undefined
* If the function has no return value or no definite return value, the call result is undefined

2.Null type

* This type also has only one value: null.
* Value null and value undifined equal ' alert (null==undefined); '//return True

* but ' alert (null===undefined); '//return FALSE, the value is equal, but the meaning is different, null means knowing what the object is looking for, but the object is not found.

* * Extension: You can use NULL or undifined to determine if an object exists on the page
' if (null)/if (undefined) {docunment.write ("true");} Else{docunment.write ("false"} '

Null and undefined return a value of false, to determine whether an element a is initialized, ' var a;if (a) {Docunment.write ("true");} Else{docunment.write ("false"} ' if returned to False indicates uninitialized.

There's also a way to ' var a;var b=a| | 9;document.write (b); ', if the return is 9, that means a is not initialized, but it is also possible to exclude the value of a and 9 in the case of equality.

3.Boolean type

* This type has 2 values: True and False

4.Number type

* The most special type in JS, which can represent either a 32-bit integer or a 64-bit floating-point number.
* Special Number value
* The outer boundary of the number value collection: Number.MAX_VALUE and Number.min_value.
* The value of number.positive_infinity is infinitely large infinity
* The value of number.negative_infinity is-infinity
* To determine if a number is poor, you can call the Isfinite () method on any number to ensure that the number is not infinite. ' If (Isfinite (a)) {alert ("finite") Else{alert ("Infinite")} '
* Nan represents a non-number, which occurs when a type (String, Boolean, etc.) conversion fails, and Nan is not equal to itself ' alert (Nan==nan) ' to return false.
* Nan belongs to number type typeof Nan--Returns number
* IsNaN () function: Check if its parameter is a non-numeric value
is a number or can be converted to a number, return False, or return True

* * Write the function, enter the 2

5.string type

* String literals are declared by double quotation marks (") or single quotation marks (')
# #二, data type conversion
-parseint (): Converts a value to an integer
* parseint ("blue")--return nan;
* parseint ("123")---return 123;
* parseint ("12.3")--Returns 12, removes the decimal part
-Parsefloat (): Convert value to floating point
-The string must represent a floating-point number in decimal form instead of octal or hexadecimal
* Parsefloat ("blue")--return nan;
* Parsefloat ("1.23")--return 1.23;
* Parsefloat ("1")--return 1, automatic removal. 0;
* Parsefloat ("01")--return 1, automatic removal. 0;
-ToString (): Converts a number to a string
-Forced type conversion
* Boolean (value): Converts the corresponding value to a Boolean type;
* Number (value): Converts the corresponding values to numbers (integer floating point can be); Converts the entire value, not the partial value
* String (value): Converts the corresponding value to a string
# #三, reference data type--Object
1.Array Class (Array object): Create an array

* Method of Creation
* ' var arr = new Array (); '
* ' var arr = new Array (10); '
* ' var arr = new Array '
* ' var arr = new array[1,2,3]; '--Common way
* Method of manipulating array
* Shift Method: Delete the first element in the array and return the element with the syntax Arr.shift (); Array length length-1
* Pop method: Delete the last element in the array and return the element with the syntax Arr.pop (); Array length length-1
* Unshift Method: Inserts the specified element in front of the array and returns the new length value of the array. The syntax is Arr.unshift () and the array length is length+1 (whether a single number or an array is inserted)
* Push method: Adds a new element to the last face of an array and returns the new length value of the array. The syntax is Arr.push () and the array length is length+1 (whether a single number or an array is inserted)
* Concat method: Combines two or more arrays to return a new array. syntax is Arr.concat (); Copy from source array * * element to result array, source array length \ value unchanged
* Splice Method: Removes one or more elements from an array and, if necessary, inserts a new element at the location of the removed element, returning the element that was removed. The syntax is arr.splice (start delete index, number of deletions, inserted element or array), array length length-number of deletions + number of elements/arrays inserted
* Reverse method: Deserializes the elements in the array and returns the array. The grammar is arr.reverse ();
* Slice method: Slice (Start,[end]): Returns a new array of entries from the original array that specify the starting subscript to the end subscript, the source array length/value is unchanged, and the slice method has been copied * * to the element specified by end, but does not include the element.
-Shift () and pop (): Returns the deleted element, array length/value change;
-Splice (): The returned element is also deleted, the inserted element is displayed directly in the array, and the length/value of the array is changed;
-Unshift () and push (): Returns the new length value of the array, changing the length/value of the array;
-Concat () and Slice (): Returns a new array with the length/value of the source array unchanged;
-Reverse: Returns the inverse of the array, the value of the array is reversed and the length is unchanged.

2.String class (String object): used to manipulate or format text strings and to determine and locate substrings in a string.

* Method of manipulating string var str= "ABCdef"
* charCodeAt method: Returns an Integer that represents the Unicode encoding of the character at the specified position. The syntax is str.charcodeat (index), and Nan is returned if no characters are specified at index.
* CharAt method: Returns the character at the specified index position. The syntax is Str.charat (index); The index value of the valid range returns an empty string.
* Slice method: Returns the fragment of a string from the specified index to the end of the index string. The syntax is Str.slice (start,[end]); Copy * * is used, the length/value of the source string is not changed.
* Substring method: Returns the substring at the specified position in the string. The syntax is str.substring (Start,[end]), with the smaller values in start and end as the starting point of the substring and the length of the substring equal to the absolute value of the difference between start and end.
* IndexOf method: Returns the character position of the substring within the string object for the first time. The syntax is str.indexof ("substring", the index to start looking for); not found--return-1;
* LastIndexOf method: Returns the position of the last occurrence of a substring of a string object. The syntax is str.lastindexof ("substring", which starts looking for index), and the search from right to left is not found--returns-1;
* Concat Method: Returns a string value that contains the connection of two or more supplied strings.

3.Global class: Is an intrinsic object that concentrates all global methods in one object

The URI that the encoding passes to the browser:

* encodeURI Method: Encodes a text string into a valid Uniform Resource Identifier (URI). The syntax is encodeURI (Uril), the full URI is processed, and special characters in the URI are not encoded, such as://?
* encodeURIComponent (): Encode all characters, including special characters
* decodeURI (): Decodes only characters replaced with encodeURI ()
* decodeURIComponent method: Decode all encodeURIComponent () encoded characters

4.Date class: Enable basic storage and obtain date and time

' var now=new date (); ' shows the current time--sat 17:08:37 gmt+0800 (China Standard Time)
Get the Year ' now.getfullyear ();
Get the Month ' now.getmonth () +1; '
Get Date ' now.getdate (); '
Get Week ' now.getday (); '
Get Hours ' now.gethours (); '
Gets the number of minutes ' now.getminutes ();
Gets the number of seconds ' now.getseconds ();

5.Math class: Is an intrinsic object that provides basic mathematical functions and constants

* Ceil method: Returns the smallest integer greater than or equal to its numeric parameter. Syntax Math.ceil (number);--Rounding up ' Math.ceil (13.1) '--return 14
* Floor Method: Returns the largest integer less than or equal to its numeric parameter. Syntax Math.ceil (number);--Rounded down ' math.ceil (13.8) '--return 13
* Round method: Returns the integer closest to the given numeric expression. Syntax Math.ceil (number);--Rounding ' Math.ceil (13.1) '--Return to ' Math.ceil (13.8) '--return 14
* Random method: Returns a pseudo-random number between 0 and 1. Grammar math.random ();
* Get a random integer between 0-200: ' Math.Round (Math.randon () *200); '

6.instanceif operator: Returns a Boolean value that indicates whether the object is an instance of a particular class.

* The difference from the typeof operator is that it requires that the object being judged must be an already defined object
* Useful when the TypeOf return value is object.
* Result = Object instanceof class, if object is an instance of class, the instanceof operator returns TRUE. Returns False if object is not an instance of the specified class, or if object is null.


























JavaScript data types

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.