search
HomeWeb Front-endFront-end Q&AAre there global functions in javascript?

Are there global functions in javascript?

Sep 07, 2021 pm 02:25 PM
javascriptglobal function

There are global functions in JS, including: decodeURI(), escape(), eval(), isFinite(), isNaN(), Number(), parseFloat(), parseInt(), String() , unescape() and so on.

Are there global functions in javascript?

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!

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
How to change the background color of a navbar in BootstrapHow to change the background color of a navbar in BootstrapAug 26, 2025 am 05:19 AM

UseBootstrap’sbuilt-inbackgroundcolorclasseslikebg-primary,bg-success,orbg-darkandpairwithnavbar-darkornavbar-lightforpropertextcontrast.2.Applycustomcolorsbyaddingacustomclasstothenavbaranddefiningthebackground-colorinCSSusinghex,RGB,orRGBAvaluesfor

What are physical and logical tags in HTML?What are physical and logical tags in HTML?Aug 26, 2025 am 05:10 AM

Physical tags are used to define the appearance of text, and logical tags are used to define the meaning of text; 1. Physical tags such as , directly control styles, but modern development recommends using CSS instead; 2. Logical tags such as , give content semantics, improve accessibility and SEO, and should be used first; 3. Modern HTML advocates the separation of structure and styles, emphasizing the combination of semantic tags and CSS to achieve a more maintainable, responsive and barrier-free web page.

How to use the meter tag in HTMLHow to use the meter tag in HTMLAug 26, 2025 am 03:44 AM

Thetagisusedtodisplayascalarmeasurementwithinaknownrange,suchasaquizscoreordiskusage,andrendersasahorizontalgauge;2.Keyattributesincludevalue(required),min,max,low,high,optimum,andtitleforaccessibility;3.Visualrangesaredefinedbylow,high,andoptimumtoi

How to animate a button with CSSHow to animate a button with CSSAug 26, 2025 am 02:17 AM

UseCSStransitionsforsmoothhovereffectsbyapplyingtransitionpropertiestobackground-color,transform,andbox-shadowtocreatesubtleanimations.2.Addscaleorcolortransformationswithtransform:scale()andcolorchangestoenhanceinteractivitywhilekeepingchangesminima

How to use article and section tags in HTMLHow to use article and section tags in HTMLAug 26, 2025 am 01:23 AM

Use tags for independent, self-containable content, such as blog posts, news stories, product lists or user comments, which can exist independently even if they are out of context; use tags for grouping related content with the same topic, usually containing a title, such as the "Services" or "Latest Articles" block in the page; 1. Emphasize the independence of the content, which can be aggregated or shared; 2. Emphasize the logical grouping of the content, which should have clear themes and titles; 3. Both can be used in nested, such as one containing multiples, or one divided into multiples; 4. Avoid using only for style, without topics or titles; 5. Correct use of these semantic tags can improve accessibility, SEO and code readability, making the web page structure clearer and easier to understand.

How to create a responsive services section with CSSHow to create a responsive services section with CSSAug 26, 2025 am 01:10 AM

StartwithsemanticHTMLusingasectioncontainerandservicecardsforclarity.2.UseCSSFlexboxorGridtocreateaflexiblelayout,withFlexboxforsimplerlayoutsandGridformorecontrol.3.Applyresponsivedesignviamediaqueries:stackcardsonsmallscreens,displaytwoperrowontabl

How to use conditional comments in HTMLHow to use conditional comments in HTMLAug 25, 2025 pm 01:43 PM

ConditionalcommentsweresupportedonlyinInternetExplorer5through9andarenotavailableinmodernbrowsersorstandards.1.TheyalloweddeveloperstotargetspecificIEversionsusingspecialHTML-likesyntaxrecognizedonlybyIE.2.Commonconditionsincluded"IE","

How to use the source element in HTMLHow to use the source element in HTMLAug 25, 2025 pm 12:03 PM

Using elements can provide multiple media formats in or in tags. The browser selects the first supported format in order and uses type attributes to avoid downloading unsupported files; 2. Using elements in the elements can load different images according to the screen size or resolution, match the conditions through the media attribute and serve as the final fallback; 3. Always add type attributes, sort source files by priority, optimize performance in responsive design, and tests across browsers to ensure compatibility, do not render content itself, and only provide optional resources for the parent element.

See all articles

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Hot Topics