global
These are global functions and objects available without loading any additional module.
Timer APIs are provided by the JSH event loop, and the console object provides standard output and
logging helpers.
setTimeout()
Execute a callback once after the specified delay in milliseconds.
If extra arguments are provided, they are passed to the callback as-is.
Syntax
setTimeout(callback, delayMs[, ...args])Return value
- A timer handle object. Pass it to
clearTimeout()to cancel execution.
Usage example
| |
clearTimeout()
Cancel a pending callback created by setTimeout() if it has not executed yet.
Calling it again for an already cancelled or already executed timer has no further effect.
Syntax
clearTimeout(timer)Usage example
| |
setInterval()
Execute a callback repeatedly at the specified interval in milliseconds.
To stop repeated execution, pass the returned handle to clearInterval().
Syntax
setInterval(callback, delayMs[, ...args])Return value
- An interval handle object. Pass it to
clearInterval()to stop repetition.
Usage example
| |
clearInterval()
Stop a repeating callback created by setInterval().
Syntax
clearInterval(interval)setImmediate()
Schedule a callback to run as soon as possible on the next event loop turn after the current execution finishes.
It is useful for lightweight asynchronous follow-up work without a timer delay.
Syntax
setImmediate(callback[, ...args])Return value
- An immediate handle object. Pass it to
clearImmediate()to cancel execution.
Usage example
| |
clearImmediate()
Cancel a pending callback created by setImmediate() if it has not executed yet.
Syntax
clearImmediate(immediate)console
The global console object provides log output and standard output helpers.
console.log()
Write an info-level log message. The output includes the INFO level prefix.
Usage example
| |
console.debug()
Write a debug-level log message.
console.info()
Write an info-level log message. It uses the same level as console.log().
console.warn()
Write a warning-level log message.
console.error()
Write an error-level log message.
console.print()
Write values without a trailing newline.
Usage example
| |
console.println()
Write values separated by spaces and append a trailing newline.
Usage example
| |
console.printf()
Write formatted output using a format string.
Syntax
console.printf(format, ...args)Usage example
| |