Standard Objects
JavaScript standard objects.
The following JavaScript standard objects are available for use in Calculations and Alerts.
Values
Infinity- Numeric property representing infinity
const a = Infinity;
const b = -Infinity;
return a === Infinity; // true
NaN- Property representing something that is not a number
const a = 1 - "string"; // NaN
return a === NaN; // true
undefined- Property representing something that is not defined
const someObject = { a: 1, b: 2 };
return someObject.c === undefined; // true
Functions
isFinite- Check if number is not Infinity
isFinite(Infinity); // false
isFinite(-Infinity); // false
isFinite(10 / 0); // false (divide by zero)
isFinite(42); // true
isFinite("abc"); // false
isNaN- Check if value is Not-A-Number
isNaN(1 - "string"); // true
isNaN(-Infinity); // false ... debatable
isNaN(42); // false
isNaN("abc"); // true
parseFloat- Parse a number from a string as a float
parseFloat("1.234"); // 1.234
parseFloat("1"); // 1.0
parseFloat("a1"); // NaN
parseInt- Parse a number from a string as an integer
parseFloat("1.234"); // 1
parseFloat("1"); // 1
parseFloat("a1"); // NaN
decodeURI- Decode a URI encoded string
const encoded = "%7B%22a%22:1,%20%22b%22:2%7D";
decodeURI(encoded); // {"a":1, "b":2}
encodeURI- Encode a string for URI
const raw = '{"a":1, "b":2}';
encodeURI(raw); // %7B%22a%22:1,%20%22b%22:2%7D
Fundamentals
Error- The standard Error Object in JavaScript
try {
const e = new Error("Im an Error");
// Properties & Methods
e.name; // 'Error'
e.message; // 'Im an Error'
e.toString(); // 'Error: Im an Error'
throw e;
} catch (error) {
console.log(error); // 'Error: Im an Error'
}
Numbers & Dates
Number- Wrapper Object for a number
const a = 123; // 123
const b = Number("123"); // returns the number 123
a === b; // true
Number("unicorn"); // NaN
Number(undefined); // NaN
// Properties & Methods
const c = 123.456789;
c.toExponential(3); // '1.235e+2'
c.toFixed(2); // 123.46
c.toPrecision(4); // 123.4
c.toString(); // '123.456789'
BigInt- Wrapper Object for integers larger than can be stored in Number
const a = 1n; // 1, note the `n` in the literal specifies this is a **BigInt**
a === 1; // false
a == 1; // true
a < 3; // true
a > 0; // true
// ... relational comparison to Number works intuitively
const b = BigInt(Number.MAX_SAFE_INTEGER); // 9007199254740991n
b * 2n; // 18014398509481982n
// Properties & Methods
const c = 123n;
c.toString(); // '123'
Date- Represents a date object. Fundamentally represented as an integer of the number of milliseconds since January 1, 1970 00:00:00 UTC
const a = Date.now(); // 1607096922047, number of milliseconds from 1/1/1970 to
// the time the statement executes
Date.parse("2020-12-04T15:52:32.939Z"); // returns a Date object for the time
// specified by the input string
new Date(); // Date object representing 'now';
new Date(value); // Date object for the milliseconds `value`
new Date(dateString); // Date object by parsing `dateString`
new Date(year, monthIndex, day, hours, minutes, seconds, milliseconds); // Date object by specifying elements
/* | -- optional -----------------------------| */
b = new Date(); // Date: 2020-12-04T15:59:00.946Z
b.getTime(); // 1607097540946
b.getUTCDate(); // 4 (day of the month 1-31)
b.getUTCDay(); // 5 (day of the week 0-6)
b.getUTCFullYear(); // 2020
b.getUTCHours(); // 15
b.getUTCMilliseconds(); // 946
b.getUTCMinutes(); // 59
b.getUTCMonth(); // 11 (month of the year 0-11)
b.getUTCSeconds(); // 0
b.toUTCString(); // 'Fri, 04 Dec 2020 15:59:00 GMT'
b.toString(); // 'Fri Dec 04 2020 09:59:00 GMT-0600 (Central Standard Time)'
b.toISOString(); // '2020-12-04T15:59:00.946Z'
b.toDateString(); // 'Fri Dec 04 2020'
b.toTimeString(); // '09:59:00 GMT-0600 (Central Standard Time)'
… plus many more: see Mozilla: Date
Math- Collection of mathematical properties and methods (works with
Number, but notBitInt)
// Constants
Math.E; // Euler's constant and the base of natural logarithms; approximately 2.718.
Math.PI; // Ratio of the a circle's circumference to its diameter; approximately 3.14159.
// Functions
Math.abs(x); // Returns the absolute value of x.
Math.ceil(x); // Returns the smallest integer greater than or equal to x.
Math.floor(x); //Returns the largest integer less than or equal to x.
Math.round(x); // Returns the value of the number x rounded to the nearest integer.
Math.sin(x); // Returns the sine of x.
Math.cos(x); // Returns the cosine of x.
Math.tan(x); // Returns the tangent of x.
Math.asin(x); // Returns the arcsine of x.
Math.acos(x); // Returns the arccosine of x.
Math.atan(x); // Returns the arctangent of x.
Math.atan2(y, x); // Returns the arctangent of the quotient of its arguments.
Math.exp(x); // Returns Ex, where x is the argument, and E is Euler's constant (2.718…, the base of the natural logarithm).
Math.log(x); //Returns the natural logarithm (ln) of x.
Math.log10(x); //Returns the base-10 logarithm of x.
Math.log2(x); //Returns the base-2 logarithm of x.
Math.max(x, ...); //Returns the largest of zero or more numbers.
Math.min(x, ...); //Returns the smallest of zero or more numbers.
Math.pow(x, y); //Returns base x to the exponent power y (that is, xy).
Math.sqrt(x); // Returns the positive square root of x.
Math.sign(x); // Returns the sign of the x, indicating whether x is positive, negative, or zero.
Math.random(); // Returns a pseudo-random number between 0 and 1.
… plus many more: see Mozilla: Math
Text
String- Wrapper Object for a string
const a = "A string ";
const b = "A string using double quotes";
const typeOfQuotes = "back-tick";
const c = `A format string using ${typeOfQuotes} quotes`; // 'A format string using back-tick quotes'
const d = new String("Another string"); // 'Another string'
a.length; // 8
a.charAt(3); // 't'
a.charCodeAt(3); // 116
a.includes("str"); // true
a.startsWith("A "); // true
a.endsWith("ing"); // false
a.indexOf("str"); // 2
a.indexOf("who"); // -1
// Return a new string ... (doesn't modify `a`)
a.toLowerCase(); // a string
a.toUpperCase(); // A STRING
a.replace("ing", "ong"); // 'A strong '
a.concat("with some more string"); // 'A string with some more string'
a.repeat(4); // 'A string A string A string A string '
a.trim(); // 'A string'
a.trimStart(); // 'A string '
a.trimEnd(); // 'A string'
a.split(" "); // [ 'A', 'string', '', '', '' ]
Indexed Collections
Array- Array of JavaScript elements
const items = ['a', 'b', 3];
const items2 = new Array(); // []
const items3 = new Array(5); // [ undefined, undefined, undefined, undefined, undefined ]
items[0]; // 'a'
Array.isArray(items); // true
Array.isArray('a'); // false
const newArray = items.concat([4, 5, 'f']); // ['a', 'b', 3, 4, 5, 'f']
newArray.every((item) => typeof item === 'string'); // false
newArray.forEach((item) => /* do something */); // returns void
newArray.map((item) => /* do something */); // returns an array with each result of `do something`
newArray.includes('b'); // true
newArray.includes('c'); // false
newArray.indexOf('b'); // 1
newArray.indexOf('c'); // -1
newArray.find((item) => item === 'b'); // 'b'
newArray.find((item) => item === 'c'); // undefined
newArray.find((item) => item > 3); // 4
newArray.findIndex((item) => item === 'b'); // 1
newArray.findIndex((item) => item === 'c'); // -1
newArray.findIndex((item) => item > 3); // 3
newArray.join(':'); // 'a:b:3:4:5:f'
const lastElement = newArray.pop(); // 'f', newArray = ['a', 'b', 3, 4, 5]
newArray.push('g'); // ['a', 'b', 3, 4, 5, 'g']
const firstElement = newArray.shift(); // 'a', newArray = ['b', 3, 4, 5, 'g']
newArray.unshift(1); // [1, 'b', 3, 4, 5, 'g']
const subArray = newArray.slice(2, 4); // [3, 4] from index 2 to less than 4 (newArray is unmodified)
const deletedElements = newArray.splice(2, 4); // [3, 4, 5, 'g'] from index 2 delete 4 elements (newArray = [1, 'b'])
const noDeletedElements = newArray.splice(2, 0, 'c', 'd', 'e'); // [] from index 2 delete 0 elements, then insert 'c', 'd', 'e' (newArray = [1, 'b', 'c', 'd', 'e'])
newArray.toString(); // '1,b,c,d,e'
newArray.reverse(); // [ 'e', 'd', 'c', 'b', 1 ] (newArray = [ 'e', 'd', 'c', 'b', 1 ])
… plus many more: see Mozilla: Array
The following typed Arrays are also available: Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array, BigInt64Array, and BigUint64Array
Keyed Collections
- Map
- See Mozilla Map
- Set
- See Mozilla Set
- WeakMap
- See Mozilla WeakMap
- WeakSet
- See Mozilla WeakSet
Miscellaneous
JSON- serialize / deserialize JSON
JSON.parse('{"a":1, "b": 2}'); // {a:1, b: 2}
JSON.stringify({ first: "first", second: "second" }); // '{"first":"first","second":"second"}'
JSON.stringify(["a", "b", "c"]); // '["a","b","c"]'
Last modified October 3, 2025: Consolidated Scripting, added Flow Example, and Fixed Typo (c4b0ec3)