# var
declare a function-scoped (hoisted) variable
var x = 1; x // => 1
node-js v0.1.0 · JavaScript on fusevm · lex/parse → AST → bytecode → Cranelift JIT · JsHost object heap · binary node · MIT · in active development
Every reserved keyword, global, and core object/type method the current node-js build recognizes, grouped by keyword set then globals then namespace then type. This page is generated from the corpus (src/lsp.rs) by the gen-docs binary, so it stays in sync with what the runtime actually knows about. Keywords mirror parser.rs; each global and method mirrors a real dispatch arm in src/builtins.rs.
vardeclare a function-scoped (hoisted) variable
var x = 1; x // => 1
letdeclare a block-scoped variable
let x = 2; x // => 2
constdeclare a block-scoped binding that cannot be reassigned
const x = 3; x // => 3
functiondefine a function (declaration or expression)
function f() { return 9; } f() // => 9
returnreturn a value from the current function (undefined if omitted)
(function () { return 7; })() // => 7
ifconditional branch on a truthy test
let x; if (true) x = 1; x // => 1
elsefallback branch of an if
let x; if (false) x = 1; else x = 2; x // => 2
whileloop while the condition is truthy
let i = 0; while (i < 3) i++; i // => 3
dodo/while loop: run the body once, then repeat while truthy
let i = 0; do { i++; } while (i < 3); i // => 3
forC-style loop, or for/of and for/in iteration
let s = 0; for (let i = 0; i < 3; i++) s += i; s // => 3
ofiterate values of an iterable: `for (x of iterable)`
let s = 0; for (const n of [1, 2, 3]) s += n; s // => 6
infor/in key iteration, and the property-membership operator
"a" in { a: 1 } // => true
switchmulti-way branch on a discriminant with case labels
let x; switch (2) { case 2: x = "b"; break; } x // => 'b'
casea labeled branch inside a switch
let x; switch (1) { case 1: x = "a"; } x // => 'a'
defaultthe fallback branch of a switch
let x; switch (9) { default: x = "d"; } x // => 'd'
breakexit the nearest enclosing loop or switch
let x; for (const n of [1, 2, 3]) { if (n === 2) break; x = n; } x // => 1
continueskip to the next iteration of the nearest loop
let s = 0; for (const n of [1, 2, 3]) { if (n === 2) continue; s += n; } s // => 4
newconstruct an instance: `new Ctor(args)`
new Error("boom").message // => 'boom'
thisthe receiver of the current call
({ n: 5, get() { return this.n; } }).get() // => 5
typeofthe type tag of a value as a string
typeof 3 // => 'number'
voidevaluate an expression and yield undefined
void 0 // => undefined
deleteremove a property from an object
const o = { a: 1 }; delete o.a; o.a // => undefined
instanceoftest whether an object was built by a constructor
new Error("e") instanceof Error // => true
throwraise an exception value
try { throw "x"; } catch (e) { e } // => 'x'
tryrun a block, routing exceptions to catch/finally
let x; try { x = 1; } finally { x = 2; } x // => 2
catchhandle an exception thrown in the try block
try { null.x; } catch (e) { "caught" } // => 'caught'
finallyblock that always runs after try/catch
let x; try { x = 1; } finally { x = 3; } x // => 3
truethe boolean true literal
true && 1 // => 1
falsethe boolean false literal
false || 2 // => 2
nullthe intentional-absence value
null ?? 5 // => 5
undefinedthe value of an unassigned binding or missing property
typeof undefined // => 'undefined'
NaNthe not-a-number float; unequal to itself
NaN === NaN // => false
Infinitythe positive-infinity float
1 / 0 === Infinity // => true
globalThisthe global object
typeof globalThis // => 'object'
parseIntparse the leading integer of a string (optional radix)
parseInt("42px") // => 42
parseFloatparse the leading floating-point number of a string
parseFloat("3.14abc") // => 3.14
isNaNtrue if the coerced number is NaN
isNaN("x") // => true
isFinitetrue if the coerced number is finite
isFinite(10) // => true
Stringconvert a value to its string form
String(123) // => '123'
Numberconvert a value to a number
Number("3.5") // => 3.5
Booleanconvert a value to its truthiness
Boolean("") // => false
Arraybuild an array from the given elements
Array(1, 2, 3) // => [ 1, 2, 3 ]
Errorconstruct a generic error with a message
new Error("boom").message // => 'boom'
TypeErrorconstruct a type error (name is 'TypeError')
new TypeError("bad").name // => 'TypeError'
RangeErrorconstruct a range error (name is 'RangeError')
new RangeError("oob").name // => 'RangeError'
console.logwrite args to stdout, space-separated, ending in a newline
console.log("hi", 1) // prints: hi 1
console.errorwrite args to stderr
console.error("oops") // prints oops to stderr
console.warnwrite args to stderr (warning channel)
console.warn("careful") // prints careful to stderr
console.infowrite args to stdout (info channel)
console.info("note") // prints note
console.debugwrite args to stdout (debug channel)
console.debug("dbg") // prints dbg
Math.PIthe ratio of a circle's circumference to its diameter
Math.PI // => 3.141592653589793
Math.absabsolute value of a number
Math.abs(-5) // => 5
Math.floorlargest integer <= x
Math.floor(3.7) // => 3
Math.ceilsmallest integer >= x
Math.ceil(3.2) // => 4
Math.roundround to the nearest integer (ties toward +Infinity)
Math.round(2.5) // => 3
Math.truncthe integer part of x, dropping any fraction
Math.trunc(-4.7) // => -4
Math.signthe sign of x as -1, 0, or 1
Math.sign(-8) // => -1
Math.sqrtsquare root of x
Math.sqrt(16) // => 4
Math.cbrtcube root of x
Math.cbrt(27) // => 3
Math.powx raised to the power y
Math.pow(2, 10) // => 1024
Math.expe raised to the power x
Math.exp(0) // => 1
Math.lognatural logarithm of x
Math.log(1) // => 0
Math.maxlargest of the arguments
Math.max(3, 1, 2) // => 3
Math.minsmallest of the arguments
Math.min(3, 1, 2) // => 1
Math.hypotthe square root of the sum of squares of the arguments
Math.hypot(3, 4) // => 5
Math.sinsine of x (radians)
Math.sin(0) // => 0
Math.coscosine of x (radians)
Math.cos(0) // => 1
Math.tantangent of x (radians)
Math.tan(0) // => 0
Math.randoma pseudo-random float in [0, 1)
Math.random() < 1 // => true
JSON.stringifyserialize a value to a JSON string
JSON.stringify({ a: 1 }) // => '{"a":1}'
JSON.parseparse a JSON string into a value
JSON.parse("[1,2]") // => [ 1, 2 ]
Object.keysan array of an object's own enumerable keys
Object.keys({ a: 1, b: 2 }) // => [ 'a', 'b' ]
Object.valuesan array of an object's own enumerable values
Object.values({ a: 1, b: 2 }) // => [ 1, 2 ]
Object.entriesan array of [key, value] pairs
Object.entries({ a: 1 }) // => [ [ 'a', 1 ] ]
Object.assigncopy source properties onto a target object (in place)
Object.assign({ a: 1 }, { b: 2 }) // => { a: 1, b: 2 }
Object.fromEntriesbuild an object from [key, value] pairs
Object.fromEntries([["a", 1]]) // => { a: 1 }
Object.freezemake an object immutable and return it
Object.freeze({ a: 1 }).a // => 1
Number.isIntegertrue if the value is an integer number
Number.isInteger(3) // => true
Number.isNaNtrue only if the value is exactly NaN (no coercion)
Number.isNaN(NaN) // => true
Number.isFinitetrue if the value is a finite number (no coercion)
Number.isFinite(10) // => true
Number.isSafeIntegertrue if the value is an integer within +/-2^53-1
Number.isSafeInteger(2 ** 53) // => false
Number.parseIntsame as the global parseInt
Number.parseInt("20", 10) // => 20
Number.parseFloatsame as the global parseFloat
Number.parseFloat("1.5") // => 1.5
String.fromCharCodea string built from the given UTF-16 code units
String.fromCharCode(65, 66) // => 'AB'
Array.isArraytrue if the value is an array
Array.isArray([1, 2]) // => true
Array.frombuild an array from an iterable or array-like
Array.from("ab") // => [ 'a', 'b' ]
Array.ofbuild an array from the given arguments
Array.of(1, 2, 3) // => [ 1, 2, 3 ]
pushappend items to the end; returns the new length
const a = [1]; a.push(2); a // => [ 1, 2 ]
popremove and return the last item
[1, 2, 3].pop() // => 3
shiftremove and return the first item
[1, 2, 3].shift() // => 1
unshiftprepend items; returns the new length
const a = [2]; a.unshift(1); a // => [ 1, 2 ]
mapa new array of the results of calling fn on each item
[1, 2, 3].map(x => x * 2) // => [ 2, 4, 6 ]
filtera new array of the items for which fn is truthy
[1, 2, 3, 4].filter(x => x % 2 === 0) // => [ 2, 4 ]
forEachcall fn on each item for effect; returns undefined
let s = 0; [1, 2, 3].forEach(x => s += x); s // => 6
reducefold the array to a single value with an accumulator
[1, 2, 3].reduce((a, b) => a + b, 0) // => 6
joinconcatenate items into a string with a separator
[1, 2, 3].join("-") // => '1-2-3'
slicea shallow copy of a [start, end) sub-range
[1, 2, 3, 4].slice(1, 3) // => [ 2, 3 ]
spliceremove/insert items in place; returns the removed items
const a = [1, 2, 3]; a.splice(1, 1); a // => [ 1, 3 ]
concata new array joining this array with more arrays/values
[1].concat([2, 3]) // => [ 1, 2, 3 ]
indexOfindex of the first matching item, or -1
[1, 2, 3].indexOf(2) // => 1
lastIndexOfindex of the last matching item, or -1
[1, 2, 1].lastIndexOf(1) // => 2
includestrue if the array contains the value
[1, 2, 3].includes(2) // => true
findthe first item for which fn is truthy, else undefined
[1, 2, 3].find(x => x > 1) // => 2
findIndexthe index of the first item for which fn is truthy, else -1
[1, 2, 3].findIndex(x => x > 1) // => 1
sometrue if fn is truthy for any item
[1, 2, 3].some(x => x > 2) // => true
everytrue if fn is truthy for every item
[1, 2, 3].every(x => x > 0) // => true
reversereverse the array in place
[1, 2, 3].reverse() // => [ 3, 2, 1 ]
sortsort in place (default: by string order)
[3, 1, 2].sort() // => [ 1, 2, 3 ]
flata new array with sub-arrays flattened one level (or by depth)
[1, [2, [3]]].flat() // => [ 1, 2, [ 3 ] ]
flatMapmap each item then flatten the result one level
[1, 2].flatMap(x => [x, x]) // => [ 1, 1, 2, 2 ]
filloverwrite a range with a value in place
[1, 2, 3].fill(0) // => [ 0, 0, 0 ]
atthe item at an index, allowing negative indexing
[1, 2, 3].at(-1) // => 3
toUpperCasea copy with all cased characters uppercased
"abc".toUpperCase() // => 'ABC'
toLowerCasea copy with all cased characters lowercased
"ABC".toLowerCase() // => 'abc'
charAtthe character at an index
"hi".charAt(1) // => 'i'
charCodeAtthe UTF-16 code unit at an index
"A".charCodeAt(0) // => 65
codePointAtthe Unicode code point at an index
"A".codePointAt(0) // => 65
slicea substring over a [start, end) range (negatives allowed)
"hello".slice(1, 3) // => 'el'
substringa substring over a [start, end) range (no negatives)
"hello".substring(0, 2) // => 'he'
splitan array of substrings split on a separator
"a,b,c".split(",") // => [ 'a', 'b', 'c' ]
trima copy with leading and trailing whitespace removed
" hi ".trim() // => 'hi'
trimStarta copy with leading whitespace removed
" hi".trimStart() // => 'hi'
trimEnda copy with trailing whitespace removed
"hi ".trimEnd() // => 'hi'
replacea copy with the first match of a substring replaced
"aaa".replace("a", "b") // => 'baa'
replaceAlla copy with every match of a substring replaced
"aaa".replaceAll("a", "b") // => 'bbb'
repeatthe string repeated n times
"ab".repeat(3) // => 'ababab'
startsWithtrue if the string starts with the prefix
"hello".startsWith("he") // => true
endsWithtrue if the string ends with the suffix
"hello".endsWith("lo") // => true
padStartpad on the left to a target length
"5".padStart(3, "0") // => '005'
padEndpad on the right to a target length
"5".padEnd(3, "0") // => '500'
toFixeda fixed-point string with n digits after the decimal point
(3.14159).toFixed(2) // => '3.14'
toPrecisiona string with n significant digits
(123.456).toPrecision(4) // => '123.5'
toStringthe string form of a number in an optional radix
(255).toString(16) // => 'ff'