JavaScript Global Functions Index

About This Index
This page is the JavaScript Global Functions index. JavaScript has 11 global functions. Each row below links to a full guide with syntax, examples you can run, and FAQs.
Learn what global functions are on /js/global. Use this page when you need a specific function such as parseInt().
Global functions need no object in front and no import: write parseInt("42", 10), not Number.parseInt(...) or window.parseInt(...). They work in the browser and in Node.js.
How to Call a Global Function
Call a global function by its name:
console.log(parseInt("42px", 10)); // 42 read a whole number
console.log(parseFloat("3.14abc")); // 3.14 read a decimal number
console.log(isNaN("hello")); // true is it NaN after converting?
console.log(isFinite(10 / 3)); // true a normal number
const url = "https://example.com/search?q=" + encodeURIComponent("a & b");
console.log(url); // ...?q=a%20%26%20b
console.log(decodeURIComponent("a%20%26%20b")); // a & b
console.log(eval("2 + 3 * 4")); // 14 run code from text (risky) JavaScript Global Functions Table
All global function guides in this JavaScript tutorial series (11 tutorials), grouped by what they do.
Turn text into numbers
2 functionsRead a number from the start of a string. Both functions stop at the first character that does not fit.
| Function | Description | Tutorial |
|---|---|---|
parseFloat() | Read a number with a decimal part from the start of a string. | Open |
parseInt() | Read a whole number from the start of a string, in any base from 2 to 36. | Open |
Check a number
2 functionsTest a value before you use it in a calculation. Both convert the value to a number first.
| Function | Description | Tutorial |
|---|---|---|
isFinite() | Return true for a normal number, and false for NaN, Infinity and -Infinity. | Open |
isNaN() | Return true when the value is NaN after it is converted to a number. | Open |
Encode and decode URLs
4 functionsMake text safe to put in a web address, and turn it back. Use the Component versions for single values.
| Function | Description | Tutorial |
|---|---|---|
decodeURI() | Decode a whole URL and keep the codes of reserved characters like / ? & =. | Open |
decodeURIComponent() | Decode one value, such as a query parameter, including reserved characters. | Open |
encodeURI() | Encode a whole URL and keep its structure characters. | Open |
encodeURIComponent() | Encode one value so it is safe inside a URL. | Open |
Run code from text
1 functionRun JavaScript that is written as a string. Powerful, but risky.
Old and deprecated
2 functionsThese still work, but you should use the URL functions above in new code.
| Function | Description | Tutorial |
|---|---|---|
escape() | Deprecated. Encode text as %XX and %uXXXX codes. | Open |
unescape() | Deprecated. Turn %XX and %uXXXX codes back into text. | Open |
Frequently Asked Questions
Start with parseInt()
Open the guide for reading whole numbers from text: syntax, examples, and FAQs.
10 people found this page helpful
