Ejscript defines a set of global variables and functions. These provide essential constants and utility functions. For a complete list, see the Global Functions and Variables page.

Global Variables

The Ejscript run-time defines the following global variables:

Variable Name Description
false False boolean value
global Global variables for this request
Infinity Floating point number set to Infinity
local Local variables
Nan Floating point number set to "Not a Number"
null Defined variable set to Null
true True boolean value
undefined Variable has no value and is set to the Undefined Value

Ejscript Functions

Ejscript defines a set of global functions. See the complete list in the Script Library API reference. Here are some of the major functions:

Script Name Syntax Examples Description
assert assert(condition) assert(x == 5) Throw an exception if the assert condition is false.
breakpoint breakpoint() breakpoint() Invoke the VM breakpoint trap routine.
deserialize deserialize(object) obj = deserialize(str) Deserialize the string and construct and equivalent object.
dump dump(...args) dump(myObj) Dump the contents of objects to the console. Useful for debugging.
eval eval(script) eval("var " + x + " = " + i) Evaluate the given script.
exit exit(status) exit(0) Immediately terminate the current script.
hashcode hashcode(obj) x = hashcode(myObj) Return a unique numeric hash code for the object
print print(...args) print("Color is " + color) Print a message to the console's stdout.
serialize serialize(object) serialize(obj) Serialize the given object into a string representation.
print print(string, ...) print("Hello World\n") Print the given strings to the web server standard output.

Types and Constructor Functions

Ejscript also defines system types as global constructor functions and class objects. The following objects are visible as global objects:

App, Application, Array, BinaryStream, Block, Boolean, ByteArray, Collection, Config, Controller, Cookie, Database, Date, Debug, Dispatcher, Error, Event, File, Function, GC, Host, Http, Iterator, JSON, Logger, Math, Memory, Name, Namespace, Null, Number, Object, Record, Reflect, RegExp, Request, Response, Session, Socket, Stream, String, TextStream, Timer, Type, Unix, UploadFile, Url, View, ViewConnector, Void, XML, XMLHttp and XMLList.

© Embedthis Software, 2003-2015. All rights reserved.