Are there global functions in javascript?
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to use WebSocket and JavaScript to implement an online speech recognition system Introduction: With the continuous development of technology, speech recognition technology has become an important part of the field of artificial intelligence. The online speech recognition system based on WebSocket and JavaScript has the characteristics of low latency, real-time and cross-platform, and has become a widely used solution. This article will introduce how to use WebSocket and JavaScript to implement an online speech recognition system.

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

Static functions are only visible within the class, without a class instance, and are used for tool class methods; while global functions are visible throughout the entire program, without a class or instance, and are used for independent functions.

Introduction to how to use JavaScript and WebSocket to implement a real-time online ordering system: With the popularity of the Internet and the advancement of technology, more and more restaurants have begun to provide online ordering services. In order to implement a real-time online ordering system, we can use JavaScript and WebSocket technology. WebSocket is a full-duplex communication protocol based on the TCP protocol, which can realize real-time two-way communication between the client and the server. In the real-time online ordering system, when the user selects dishes and places an order

How to use WebSocket and JavaScript to implement an online reservation system. In today's digital era, more and more businesses and services need to provide online reservation functions. It is crucial to implement an efficient and real-time online reservation system. This article will introduce how to use WebSocket and JavaScript to implement an online reservation system, and provide specific code examples. 1. What is WebSocket? WebSocket is a full-duplex method on a single TCP connection.

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

Usage: In JavaScript, the insertBefore() method is used to insert a new node in the DOM tree. This method requires two parameters: the new node to be inserted and the reference node (that is, the node where the new node will be inserted).
