Global functions
encodeURI () decodeURI () encodeURIComponent () decodeuricomponent () Escape () unescape () eval ()
String () Number () parseint () parsefloat ()
IsNaN () isfinite ()
encodeURI (URI): encodes a string as a URI. Use the decodeURI () method to encode a URI (Common resource identifier: Uniform Resource Identifier, referred to as "uri"). The encodeURI () function is not escaped for the following ASCII punctuation mark with special meanings in the URI: ,/?: @ & = + $ #(you can use the encodeURIComponent () method to separate specific Encoding of the ASCII punctuation mark. )。 decodeURI (URI): Decodes an encoded URI.
var textStr=‘http://www.zhuan-qian.com?url=http://xiao_da.com&name=花钱#index‘; var newStr1=encodeURI(textStr); console.log(newStr1); -- http://www.zhuan-qian.com?url=http://xiao_da.com&name=%E8%8A%B1%E9%92%B1#index
encodeURIComponent (URI): encodes a string as a URI component. The method does not encode ASCII letters and numbers, nor does it encode these ASCII punctuation marks: -_.! ~ * ' () . Other characters (such as:;/?:@&=+$,# These punctuation marks used to separate the URI component) will be replaced by one or more hexadecimal escape sequences. decodeURIComponent (): Decodes a coded URI component
var textStr=‘http://www.zhuan-qian.com?url=http://xiao_da.com&name=花钱#index‘; var newStr1=encodeURIComponent(textStr); console.log(newStr1); -- http%3A%2F%2Fwww.zhuan-qian.com%3Furl%3Dhttp%3A%2F%2Fxiao_da.com%26name%3D%E8%8A%B1%E9%92%B1%23index
Escape (): encodes the string. The function encodes the string so that it can be read on all computers. The method does not encode ASCII letters and numbers, nor does it encode the following ASCII punctuation marks: * @-_ +. All other characters will be replaced by escape sequences. The function cannot be used for encoding URIs (Universal Resource Identifier (Uniformresourceidentifier, "URI")). Unescape (): Decoding a string encoded by escape ()
var textStr=‘[email protected]#$-_32测试/?,.‘; var newStr1=escape(textStr); console.log(newStr1); -- [email protected]%23%24-_32%u6D4B%u8BD5/%3F%2C.
eval (): executes the JavaScript string as a script. If the argument is an expression, the eval () function executes the expression. If the parameter is a JavaScript statement, Eval () executes the JavaScript statement. The eval () function is a dynamic code executed by a function that is much slower than executing a script directly. Use the eval () function carefully, as far as possible, to ensure the security of the program.
string (): Converts the value of an object to a string
Number () converts the value of the object to numbers, and the number () function returns Nan if the value of the object cannot be converted to numbers. If the parameter's date object, number () returns the milliseconds from January 1, 1970 through to the present
parseint (String,radix): returns the value converted to an integer.
Note: When the value of the parameter radix is 0, or the parameter is not set, parseint () determines the cardinality of the number based on string. When you omit the Radix,javascript default number, the cardinality rule is:
- If string starts with 0x, parseint () resolves the remainder of the string to a 16-binary integer.
- If string starts with 0, then ECMAScript V3 allows an implementation of parseint () to parse subsequent characters into octal or hexadecimal numbers.
- If string starts with a 1~9 number, parseint () resolves it to a decimal integer.
- If the string starts with a valid character, parseint () intercepts the legal characters.
- Whitespace at the beginning and end of a string is allowed.
- If the first character of a string cannot be converted to a number, parseint () returns Nan.
- The old browser uses the octal cardinality by default when the string starts with "0". ECMAScript 5, the default is the decimal base.
parsefloat (String): returns the value converted to a floating-point type.
The function specifies whether the first character in a string is a number. If it is, the string is parsed until the end of the number is reached, and then the number is returned as a number, not as a string.
IsNaN (value): detects whether a value is Nan. IsNaN () detects if the value is a non-numeric value, and returns True if the values are Nan, otherwise false.
isfinite (value): detects whether a value is infinite. If value is Nan or the number of +infinity or-infinity, Isfinite () returns false.
Global Properties
Infinity: The Infinity property is used to hold numeric values that represent positive infinity. Negative infinity is a numeric value that represents a negative infinity. In JavaScript, values that exceed 1.7976931348623157E+10308 are infinity, and values less than -1.7976931348623157E+103088 are infinitely small.
NaN: The NaN property is used to refer to special non-numeric values. This property specifies a number that is not illegal. The NaN property is the same as the Number.NaN property. Use IsNaN () to determine whether a value is a number. The reason is that NaN is not equal to all values, including itself.
undefined: for storing values that are not defined in JavaScript.
JS's global function