Simple instructions for using JavaScript global functions_Basic knowledge
- WBOYOriginal
- 2016-05-16 18:09:461006browse
1. decodeURI() parameter: string
Function description: Decode the URI encoded by the encodeURI() function.
Example:
can decode http://www.jb51.net/My first/ to http://www.jb51.net/My first/
2. decodeURIComponent() parameter: string
Function description: The function can decode the URI encoded by the encodeURIComponent() function.
3. encodeURI() parameter: string
Function description: String can be encoded as URI.
Tip: If the URI component contains delimiters, such as ? and #, you should use the encodeURIComponent() method to encode each component separately.
4. encodeURIComponent()
Function description: Strings can be encoded as URI components.
Note that the encodeURIComponent() function differs from the encodeURI() function in that the former assumes that its arguments are part of a URI (such as protocol, hostname, path, or query string).
So the encodeURIComponent() function will escape the punctuation that separates the parts of the URI.
5. escape() parameter: string
Function description: The string can be encoded so that the string can be read on all computers. This method does not encode ASCII letters and numbers, nor does
encode the following ASCII punctuation characters: - _ . ! ~ * ' ( ) . All other characters will be replaced by escape sequences.
Warm reminder: ECMAScript v3 deprecates the use of this method, the application uses decodeURI() and decodeURIComponent() to replace it.
6. unescape() parameter: string
Function description: The string encoded by escape() can be decoded. The function works like this: by finding character sequences of the form %xx and %uxxxx (x represents a hexadecimal number),
replacing such character sequences with the Unicode characters u00xx and uxxxx decoding.
Warm reminder: ECMAScript v3 has removed the unescape() function from the standard and deprecated its use, so it should be replaced by decodeURI() and decodeURIComponent().
7. eval() parameter: string
Function description: It can calculate a certain string and execute the JavaScript code in it.
Example:
document.write(eval("12 2")) will output 14
Note: The parameter must be of type string, otherwise the method will return without any changes .
8. isFinite() parameter: number
Function description: Used to check whether its parameters are finite.
Returns true if number is a finite number (or convertible to a finite number). Otherwise, if number is NaN (not a number), or a positive or negative infinity number, false is returned.
Example:
isFinite(-125) and isFinite(1.2) return true,
while isFinite('Yi Shuihan') and isFinite('2011-3-11') return false.
9. isNaN() parameters: unlimited
Function description: The function is used to check whether its parameter is a non-numeric value.
Example:
isNaN(123) and isNaN(0) return false
isNaN("Yi Shuihan") and isNaN("100") return true.
Note: you can use isNaN() function to detect arithmetic errors, such as dividing by 0.
10. Number() parameters: unlimited
Function description: Convert the value of the object into a number. If the argument is a Date object, Number() returns the number of milliseconds since January 1, 1970. If the object's value cannot be converted to a number, the Number() function returns NaN. Example:
var test1= new Boolean(true);
var test2= new Boolean(false);
var test3= new Date();
var test4= new String("999") ;
var test5= new String("999 888");
document.write(Number(test1)); Output 1
document.write(Number(test2)); Output 0
document.write(Number(test3)); output 1256657776588
document.write(Number(test4)); output 999
document.write(Number(test5)); output NaN
and
parseFloat() parseInt() String() Will add more later!
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn