There are global functions in JS, including: decodeURI(), escape(), eval(), isFinite(), isNaN(), Number(), parseFloat(), parseInt(), String() , unescape() and so on.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
JavaScript Global Function
Function | Description |
---|---|
decodeURI() | Decode an encoded URI. |
decodeURIComponent() | Decode an encoded URI component. |
encodeURI() | Encode a string into a URI. |
encodeURIComponent() | Encode a string into a URI component. |
escape() | Encode the string. |
eval() | Evaluates a JavaScript string and executes it as script code. |
isFinite() | Check whether a value is a finite number. |
isNaN() | Checks whether a value is a number. |
Number() | Convert the value of the object to a number. |
parseFloat() | Parse a string and return a floating point number. |
parseInt() | Parse a string and return an integer. |
String() | Convert the value of the object to a string. |
unescape() | Decode the string encoded by escape(). |
decodeURI() function
decodeURI() function can decode the URI encoded by the encodeURI() function.
Syntax: decodeURI(uri)
uri: required. A string containing the URI to decode or other text to decode.
decodeURIComponent() function
decodeURIComponent() function can decode the URI encoded by the encodeURIComponent() function.
Syntax: decodeURIComponent(uri)
encodeURI() function
encodeURI() function can use strings as URIs Encode.
The encodeURI() function will not escape the following ASCII punctuation symbols that have special meanings in URIs: , / ? : @ & = $ # (You can use the encodeURIComponent() method to separately The meaning of ASCII punctuation is encoded.).
Syntax: encodeURI(uri)
encodeURIComponent() function
The encodeURIComponent() function encodes a string as a URI component.
This method does not encode ASCII letters and numbers, nor does it encode these ASCII punctuation characters: - _ . ! ~ * ' ( ) .
Other characters (such as :;/?:@&= $,# these punctuation marks used to separate URI components) are replaced by one or more hexadecimal escape sequences.
Syntax: encodeURIComponent(uri)
escape() function
escape() function can encode strings , so that the string can be read on all computers.
This method does not encode ASCII letters and numbers, nor does it encode the following ASCII punctuation characters: * @ - _ . / . All other characters will be replaced by escape sequences.
Syntax: escape(string)
string: required. The string to be escaped or encoded.
eval() function
eval() function evaluates a JavaScript string and executes it as script code.
If the parameter is an expression, the eval() function will execute the expression. If the argument is a Javascript statement, eval() will execute the Javascript statement.
Syntax: eval(string)
isFinite() function
isFinite() function is used to check whether its parameters It is infinity, which can also be understood as whether it is a finite number.
Syntax: isFinite(value)
value: required. The number to detect.
Return value: If the parameter is NaN, positive infinity or negative infinity, false will be returned, otherwise true will be returned.
isNaN() function
isNaN() function is used to check whether its argument is a non-numeric value.
Syntax: isNaN(value)
If the parameter value is NaN or a non-numeric value such as string, object, undefined, etc., it returns true, otherwise it returns false.
Number() function
Number() function converts the value of an object into a number.
Syntax: Number(object)
If the value of the object cannot be converted to a number, the Number() function returns NaN.
parseFloat() function
The parseFloat() function parses a string and returns a floating point number.
This function specifies whether the first character in the string is a number. If it is, the string is parsed until it reaches the end of the number, and the number is returned as a number rather than as a string.
Syntax: parseFloat(string)
parseInt() function
parseInt() function can parse a string, and returns an integer.
Syntax: parseInt(string, radix)
When the value of parameter radix is 0, or the parameter is not set, parseInt() will judge the number based on string of base.
When the parameter radix is omitted, JavaScript defaults to the radix of numbers as follows:
If the string starts with "0x", parseInt() will parse the rest of the string into ten Hexadecimal integer.
If string starts with 0, then ECMAScript v3 allows an implementation of parseInt() to parse the following characters as octal or hexadecimal digits.
If string starts with a number from 1 to 9, parseInt() will parse it into a decimal integer.
String() function
String() function converts the value of an object into a string.
Syntax: String(object)
unescape() function
unescape() function can be passed escape() The encoded string is decoded.
Syntax: unescape(string)
Note: unescape() cannot be used to decode URI (UniformResourceIdentifier, referred to as "URI") . To decode a URI please use the decodeURI() method.
[Recommended learning: javascript advanced tutorial]
The above is the detailed content of Are there global functions in javascript?. For more information, please follow other related articles on the PHP Chinese website!