JavaScript Global Functions

Beginner
8 min read
Updated: Nov 2026
3 examples
Built-in functions

Definition and Usage

Global functions are functions that JavaScript gives you for free. You call them by name, parseInt("42", 10), with no object in front and nothing to import. They work anywhere in your code: in a browser, in Node.js, in Deno and in Bun.

They belong to the global object, which you can reach as globalThis. In a browser that object is window. There are 11 of them, and they do three kinds of jobs: turn text into numbers, check numbers, and encode or decode text for URLs. One of them, eval(), runs code that is written as text.

This page explains the idea. The Global Functions index links the full guide for each function, with syntax, three runnable examples and FAQs.

Two of them are deprecated.

escape() and unescape() are old and should not be used in new code. eval() still works, but it is risky. Use encodeURIComponent() and JSON.parse() instead.

JavaScript Syntax

Call a global function by its name. Here are five of them at work:

JavaScript
console.log(parseInt("42px", 10));              // 42      text -> whole number
console.log(parseFloat("3.14abc"));             // 3.14    text -> decimal number
console.log(isNaN("hello"));                    // true    is it "not a number"?
console.log(isFinite(10 / 0));                  // false   Infinity is not finite
console.log(encodeURIComponent("a & b"));       // a%20%26%20b   safe for a URL
console.log(decodeURIComponent("a%20%26%20b")); // a & b

Core Ideas

Ideas every global function tutorial in this series builds on:

IdeaExampleRemember
Global functionparseInt("42", 10)Called by name, with no object in front
globalThisglobalThis.parseIntThe global object that holds these functions (window in a browser)
ConversionisNaN("42")Some functions turn the value into a number before they test it
NaN0 / 0The result of a number calculation that has no answer
Infinity10 / 0The result of dividing by zero, or of a number that is too big
RadixparseInt("ff", 16)The number base used to read text, from 2 to 36
Percent code%20How a character is written inside a URL (%20 is a space)
Deprecatedescape("a b")Still works, but you should not use it in new code

Global Function or Number Method?

Four of the global functions have a twin on the Number object. Only two of the pairs are really the same function:

Global functionNumber versionSame function?
parseInt()Number.parseInt()Yes, they are the same function
parseFloat()Number.parseFloat()Yes, they are the same function
isNaN()Number.isNaN()No. The global one converts first, the Number one does not
isFinite()Number.isFinite()No. The global one converts first, the Number one does not

For checks, prefer Number.isNaN() and Number.isFinite(), because they never change the value first. isNaN("hello") is true only because the text is converted to NaN; Number.isNaN("hello") is false.

How Global Functions Work

No object in front

Write the name and the parentheses: parseFloat("3.5"). You do not write Math. or Number. before it, and nothing needs to be imported.

They live on the global object

Each function is a property of globalThis, so globalThis.parseInt === parseInt is true. Be careful not to create your own variable with the same name, because it would hide the built-in function.

Text readers stop early

parseInt() and parseFloat() read from the left and stop at the first character that does not fit, so "42px" still gives 42. The result is NaN when the text does not start with a number.

Checks convert first

isNaN() and isFinite() turn the value into a number before they answer. That is why isNaN("") is false: empty text becomes 0.

Encode out, decode in

Use encodeURIComponent() for each value you put into a URL, and decodeURIComponent() for each value you read from one. Encode once and decode once.

Do not run text you do not trust

eval() runs any code you give it. If the text came from a user, it can run their code. Use JSON.parse() for data instead.

Real-Life Uses

Global functions are small helpers that you will use in almost every project. Typical places:

UseWhat it does
Read form valuesA text box always gives text. Use parseInt() or parseFloat() to get a number you can add and compare.
Check a calculationUse isNaN() or isFinite() before you show a result, so a bad input shows a message and not NaN.
Build links and requestsUse encodeURIComponent() for search words and names so spaces and symbols cannot break the URL.
Read URL parametersUse decodeURIComponent() to turn the values from an address back into the text the user typed.

JavaScript Examples

Three short programs. Each one prints plain text, so the output is the same in Node.js and in the browser console.

Example 1 — Turn Text into Numbers

Values from a form arrive as text. Convert them, calculate, and check the result.

JavaScript
const quantityText = "3";
const priceText = "19.99 USD";

const quantity = parseInt(quantityText, 10);
const price = parseFloat(priceText);
const total = quantity * price;

console.log("Quantity: " + quantity);
console.log("Price: " + price);
console.log("Total is finite: " + isFinite(total));
console.log("Total: " + total.toFixed(2));
console.log("'free' is NaN: " + isNaN(parseFloat("free")));

How It Works

  1. Text in, numbers out. parseInt("3", 10) gives the whole number 3. parseFloat("19.99 USD") reads 19.99 and ignores the letters.
  2. Calculate and check. Multiply the two numbers, then ask isFinite(total) whether the result is a normal number. It is, so the answer is true.
  3. Format for display. toFixed(2) shows the total with two decimals, 59.97.
  4. Bad input. parseFloat("free") cannot read a number, so it gives NaN, and isNaN() reports true.

Example 2 — Build and Read a Safe URL

Encode the values when you build the address, and decode them when you read it.

JavaScript
const word = "rock & roll";
const place = "New York";

const url = "https://example.com/search?q=" + encodeURIComponent(word) +
  "&city=" + encodeURIComponent(place);
console.log(url);

const query = url.split("?")[1];
query.split("&").forEach(function (pair) {
  const parts = pair.split("=");
  console.log(parts[0] + " = " + decodeURIComponent(parts[1]));
});

How It Works

  1. Encode each value. The space becomes %20 and the & in "rock & roll" becomes %26, so it cannot be mistaken for a new parameter.
  2. Join the parts. The real & between the two parameters is added after encoding.
  3. Split first, decode second. The query is split on & and =, and then each value goes through decodeURIComponent(), which gives back the original text.

Example 3 — Find the Functions on globalThis

The global functions are properties of the global object. Compare them with their Number twins.

JavaScript
console.log("typeof parseInt: " + typeof parseInt);
console.log("On globalThis: " + (globalThis.parseInt === parseInt));
console.log("Number.parseInt is the same: " + (Number.parseInt === parseInt));
console.log("Number.isNaN is the same: " + (Number.isNaN === isNaN));

console.log("isNaN('abc'): " + isNaN("abc"));
console.log("Number.isNaN('abc'): " + Number.isNaN("abc"));
isNaN() tutorial

How It Works

  1. They are functions. typeof parseInt is "function".
  2. They live on the global object. globalThis.parseInt is the very same function as parseInt.
  3. Some twins are identical. Number.parseInt and parseInt are one function with two names.
  4. Some twins are different. Number.isNaN is a separate, stricter function. For the text "abc" the global one says true (after converting) and the Number one says false.

The Global Functions

There are 11 global functions. Each one has its own tutorial:

FunctionWhat it does
decodeURI()Decode a whole URL and keep the codes of reserved characters.
decodeURIComponent()Decode one value, such as a query parameter.
encodeURI()Encode a whole URL and keep its structure.
encodeURIComponent()Encode one value so it is safe inside a URL.
escape()Deprecated: encode text as %XX and %uXXXX codes.
eval()Run JavaScript code that is written as text (risky).
isFinite()Check that a value is a normal number, not NaN or Infinity.
isNaN()Check whether a value is NaN after converting it to a number.
parseFloat()Read a decimal number from the start of a string.
parseInt()Read a whole number from the start of a string.
unescape()Deprecated: turn %XX and %uXXXX codes back into text.

Full list: Global Functions index.

Frequently Asked Questions

They are built-in functions that you can call by name from anywhere in your code, without an object in front and without an import. Examples are parseInt(), parseFloat(), isNaN(), isFinite(), encodeURIComponent() and eval(). They are properties of the global object, globalThis.
This series covers 11: decodeURI(), decodeURIComponent(), encodeURI(), encodeURIComponent(), escape(), eval(), isFinite(), isNaN(), parseFloat(), parseInt() and unescape(). Browsers add many more, such as setTimeout() and fetch(), but those belong to the browser, not to the JavaScript language.
None. They are the same function, so Number.parseInt === parseInt is true. The same is true for parseFloat() and Number.parseFloat(). isNaN() and isFinite() are different from Number.isNaN() and Number.isFinite(), because the global versions convert the value first.
Avoid escape() and unescape(), which are deprecated; use encodeURIComponent() and decodeURIComponent() instead. Avoid eval() unless you are sure the text is safe, because it runs any code it is given. For data, use JSON.parse().
Yes. The functions in this series are part of the JavaScript language itself, so they work the same in browsers, Node.js, Deno and Bun. In Node.js the global object is also called globalThis (or global).

Browse the global functions

Open the index for all 11 global functions: syntax, runnable examples, and FAQs.

Global Functions index →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

15 people found this page helpful