1.Number
JavaScript has only one numeric type, can have decimals or not, and can use scientific notation.
var y=123e5; // 12300000 var z=123e-5; // 0.00123
JavaScript is not a type language. Unlike many other programming languages, JavaScript does not define different types of numbers, such as integers, short, long, floating point, and so on.
All the numbers in JavaScript are stored as 64 bits (8 bits) of the root 10, floating-point numbers.
If the prefix is 0, JavaScript interprets numeric constants as octal numbers, and if the prefixes are 0 and "X", they are interpreted as hexadecimal numbers.
var y=0377; var z=0xff;
Y is the octal count, and Z is the 16 binary count.
You can create a number object with the following code
var mynum=New number (value); var mynum=number (value);
The number object has the following properties and methods:
Number object property
Properties |
Description |
Constructor |
Returns a reference to the number function that created this object. |
Max_value |
The maximum number that can be represented. |
Min_value |
The smallest number that can be represented. |
NaN |
Non-numeric value. |
Negative_infinity |
Negative infinity, which returns this value when overflow. |
Positive_infinity |
Positive infinity, which returns this value when overflow. |
Prototype |
gives you the ability to add properties and methods to an object. |
Number Object method
Method |
Description |
Tostring |
Converts a number to a string, using the specified cardinality. |
toLocaleString |
Converts a number to a string, using the local number format order. |
ToFixed |
Converts a number to a string, the result of which has a specified number of digits after the decimal point. |
Toexponential |
Converts the value of an object to an exponential count method. |
Toprecision |
Formats the number as the specified length. |
ValueOf |
Returns the base numeric value of a number object. |
2.String
The string object is used to manipulate text (strings).
New String (s); String (s);
String Object Properties
Properties |
Description |
Constructor |
A reference to the function that created the object |
Length |
The length of the string |
Prototype |
Allows you to add properties and methods to an object |
String Object method
Method |
Description |
Anchor () |
Creates an HTML anchor. |
Big () |
Displays the string in a large font. |
Blink () |
Displays the flashing string. |
Bold () |
Use bold to display the string. |
CharAt () |
Returns the character at the specified position. |
charCodeAt () |
Returns the Unicode encoding of the character at the specified position. |
Concat () |
The connection string. |
Fixed () |
Displays the string as a typewriter text. |
FontColor () |
Displays the string using the specified color. |
FontSize () |
Displays the string using the specified dimensions. |
fromCharCode () |
Creates a string from character encoding. |
IndexOf () |
Retrieves a string. |
Italics () |
Use italic to display strings. |
LastIndexOf () |
The string is searched forward from the back. |
Link () |
Displays the string as a link. |
Localecompare () |
Compares two strings in a local-specific order. |
Match () |
Finds a match for one or more regular expressions. |
Replace () |
Replace the substring that matches the regular expression. |
Search () |
Retrieves a value that matches a regular expression. |
Slice () |
Extracts a fragment of a string and returns the extracted part in a new string. |
Small () |
Use a small font size to display the string. |
Split () |
Splits a string into an array of strings. |
Strike () |
Use strikethrough to display strings. |
Sub () |
Displays the string as subscript. |
SUBSTR () |
Extracts a specified number of characters from the starting index number in a string. |
SUBSTRING () |
Extracts the characters between two specified index numbers in a string. |
SUP () |
Displays the string as superscript. |
toLocaleLowerCase () |
Converts the string to lowercase. |
toLocaleUpperCase () |
Converts the string to uppercase. |
toLowerCase () |
Converts the string to lowercase. |
toUpperCase () |
Converts the string to uppercase. |
Tosource () |
Represents the source code for the object. |
ToString () |
Returns a string. |
ValueOf () |
Returns the original value of a string object. |
3.Date
The Date object is used to process dates and times.
var mydate=New Date ()
Date Object Properties
Properties |
Description |
Constructor |
Returns a reference to the Date function that created this object. |
Prototype |
gives you the ability to add properties and methods to an object. |
Date Object method
Method |
Description |
Date () |
Returns the date and time of day. |
GetDate () |
Returns the day of the one month (1 ~ 31) from the Date object. |
GetDay () |
Returns the day of the week from a Date object (0 ~ 6). |
GetMonth () |
Returns the month (0 ~ 11) from the Date object. |
getFullYear () |
Returns the year as a four-digit number from a Date object. |
GetYear () |
Please use the getFullYear () method instead. |
GetHours () |
Returns the hour (0 ~ 23) of the Date object. |
Getminutes () |
Returns the minute (0 ~ 59) of the Date object. |
Getseconds () |
Returns the number of seconds (0 ~ 59) of the Date object. |
Getmilliseconds () |
Returns the milliseconds (0 ~ 999) of the Date object. |
GetTime () |
Returns the number of milliseconds since January 1, 1970. |
getTimezoneOffset () |
Returns the minute difference between local time and Greenwich Mean Time (GMT). |
getUTCDate () |
Returns the day of the month from the Date object according to the world (1 ~ 31). |
GetUTCDay () |
Returns the day of the week from the Date object according to the world (0 ~ 6). |
getUTCMonth () |
Returns the month (0 ~ 11) from the Date object according to the world. |
getUTCFullYear () |
Returns a four-digit year from a Date object, based on the world. |
getUTCHours () |
Returns the hour (0 ~ 23) of the Date object according to the universal. |
getUTCMinutes () |
Returns the minute (0 ~ 59) of the Date object according to the universal. |
getUTCSeconds () |
Returns the seconds (0 ~ 59) of a Date object according to the universal. |
getUTCMilliseconds () |
Returns the milliseconds (0 ~ 999) of a Date object according to the universal. |
Parse () |
Returns the number of milliseconds from midnight January 1, 1970 to the specified date (string). |
SetDate () |
Sets the day of the month in the Date object (1 ~ 31). |
Setmonth () |
Sets the month (0 ~ 11) in the Date object. |
setFullYear () |
Sets the year (four digits) in the Date object. |
Setyear () |
Please use the setFullYear () method instead. |
Sethours () |
Sets the hour (0 ~ 23) in the Date object. |
Setminutes () |
Sets the minute (0 ~ 59) in the Date object. |
Setseconds () |
Sets the second (0 ~ 59) in the Date object. |
Setmilliseconds () |
Sets the milliseconds (0 ~ 999) in the Date object. |
SetTime () |
Sets the Date object in milliseconds. |
SetUTCDate () |
Sets the day of the month in the Date object according to the world time (1 ~ 31). |
setUTCMonth () |
Sets the month (0 ~ 11) in the Date object according to the world time. |
setUTCFullYear () |
Sets the year (four digits) in the Date object according to the world time. |
setUTCHours () |
Sets the hour in the Date object according to the world time (0 ~ 23). |
setUTCMinutes () |
Sets the minute (0 ~ 59) in the Date object according to the world. |
setUTCSeconds () |
Sets the seconds in the Date object according to the world time (0 ~ 59). |
setUTCMilliseconds () |
Sets the milliseconds (0 ~ 999) in the Date object according to the world time. |
Tosource () |
Returns the source code for the object. |
ToString () |
Converts a Date object to a string. |
toTimeString () |
Converts the time portion of a Date object to a string. |
toDateString () |
Converts the date part of a Date object to a string. |
toGMTString () |
Please use the toutcstring () method instead. |
toUTCString () |
Converts a Date object to a string, depending on the universal. |
toLocaleString () |
Converts a Date object to a string, based on the local time format. |
toLocaleTimeString () |
Converts the time portion of a Date object to a string, based on the local time format. |
toLocaleDateString () |
Converts the date part of a DateTime object to a string, based on the local time format. |
UTC () |
Returns the number of milliseconds from January 1, 1970 to the specified date, depending on the time. |
ValueOf () |
Returns the original value of the Date object. |
Note: When you manipulate dates, you can add a number directly to a specified date using the following method, which is automatically completed by JavaScript when the date operation changes the month or year.
var mydate=New Date () mydate.setdate (Mydate.getdate ()+5)
4.Array
The Array object is used to store multiple values in a single variable.
New Array (); New Array (size); New Array (element0, Element1, ..., ELEMENTN);
Array Object Properties
Properties |
Description |
Constructor |
Returns a reference to the array function that created this object. |
Length |
Sets or returns the number of elements in the array. |
Prototype |
gives you the ability to add properties and methods to an object. |
Array Object method
Method |
Description |
Concat () |
Joins two or more arrays and returns the result. |
Join () |
Put all the elements of the array into a string. element is delimited by the specified delimiter. |
Pop () |
Delete and return the last element of the array |
Push () |
Adds one or more elements to the end of the array and returns the new length. |
Reverse () |
Reverses the order of the elements in the array. |
Shift () |
Delete and return the first element of the array |
Slice () |
Returns the selected element from an existing array |
Sort () |
Sorting elements of an array |
Splice () |
Deletes the element and adds a new element to the array. |
Tosource () |
Returns the source code for the object. |
ToString () |
Converts the array to a string and returns the result. |
toLocaleString () |
Converts the array to a local array and returns the result. |
Unshift () |
Adds one or more elements to the beginning of the array and returns the new length. |
ValueOf () |
Returns the original value of an array object |
5.Boolean
A Boolean object represents two values: "True" or "false".
New Boolean (value); // constructor Function Boolean (value); // Conversion Functions
Note: If the value parameter is omitted, or is set to 0,-0, NULL, "", false, undefined, or NaN, the object is set to False. Otherwise set to true (even if the value parameter is the string "false").
Boolean Object Properties
Properties |
Description |
Constructor |
Returns a reference to the Boolean function that created this object |
Prototype |
gives you the ability to add properties and methods to an object. |
Boolean Object method
Method |
Description |
Tosource () |
Returns the source code for the object. |
ToString () |
Converts the logical value to a string and returns the result. |
ValueOf () |
Returns the original value of a Boolean object. |
6.Math
The Math object is used to perform mathematical tasks. Like the following code, math is a tool class, so no constructors are provided, and all properties and methods under math can be called directly from the class name.
var pi_value=Math.PI; var sqrt_value=math.sqrt (15);
Math Object Properties
Properties |
Description |
E |
Returns the arithmetic constant E, which is the base of the natural logarithm (approximately equal to 2.718). |
LN2 |
Returns the natural logarithm of 2 (approximately equal to 0.693). |
LN10 |
Returns the natural logarithm of 10 (approximately equal to 2.302). |
Log2e |
Returns the logarithm of E with a base of 2 (approximately equal to 1.414). |
log10e |
Returns the logarithm of E with a base of 10 (approximately equal to 0.434). |
Pi |
Returns the Pi (approximately equal to 3.14159). |
Sqrt1_2 |
Returns the reciprocal of the square root that returns 2 (approximately equals 0.707). |
SQRT2 |
Returns the square root of 2 (approximately equal to 1.414). |
Math Object method
Method |
Description |
ABS (x) |
The absolute value of the return number. |
ACOs (x) |
The inverse cosine value of the returned number. |
ASIN (x) |
Returns the inverse chord value of the number. |
Atan (x) |
Returns the inverse tangent of x with a value between-PI/2 and PI/2 radians. |
ATAN2 (y,x) |
Returns the angle from the x-axis to the point (X, y) (between-PI/2 and PI/2 radians). |
Ceil (x) |
The logarithm is rounded up. |
COS (x) |
The cosine of the returned number. |
EXP (x) |
Returns the exponent of E. |
Floor (x) |
The logarithm is rounded down. |
Log (x) |
Returns the natural logarithm of the number (bottom is e). |
Max (x, y) |
Returns the highest value in X and Y. |
Min (x, y) |
Returns the lowest value in X and Y. |
Pow (x, y) |
Returns the Y power of X. |
Random () |
Returns a random number between 0 and 1. |
Round (x) |
Rounds the number to the nearest integer. |
Sin (x) |
Returns the sine of a number. |
sqrt (x) |
Returns the square root of the number. |
Tan (x) |
Returns the tangent of a corner. |
Tosource () |
Returns the source code for the object. |
ValueOf () |
Returns the original value of the Math object. |
7.RegExp
REGEXP is the abbreviation for regular expressions.
var patt1=New RegExp ("E");
The RegExp object has 3 methods: Test (), exec (), and compile ().
Test ()
The test () method retrieves the specified value in the string. The return value is true or false.
EXEC ()
The EXEC () method retrieves the specified value in the string. The return value is the value that was found. If no match is found, NULL is returned.
You can add a second parameter to the RegExp object to set the retrieval. For example, if you need to find all the existence of all a character, you can use the "G" parameter ("global").
When using the "G" parameter, the EXEC () works as follows:
- Find the first "E" and store its location
- If you run EXEC () again, retrieve it from the stored location and find the next "E" and store its location
var patt1=New RegExp ("E", "G"); Do {result=patt1.exec ("The Best Things is Free");d ocument.write (result); while (result!=null
Compile ()
The compile () method is used to change the REGEXP.
Compile () can either change the retrieval mode or add or remove the second parameter.
var patt1=New RegExp ("E");d ocument.write (Patt1.test ("The best things on life is free" ) );p att1.compile ("D");d ocument.write (Patt1.test ("The best things on life is Free");
Modifier
modifier |
Description |
I |
Performs a match that is not case sensitive. |
G |
Performs a global match (finds all matches rather than stops after the first match is found). |
M |
Performs multi-line matching. |
JavaScript Learning Note (--javascript) built-in objects