Predeclared in MISC

Constants

(constant) Infinity :number

The name Infinity refers to the special number value Infinity. See ECMAScript Specification, Section 4.3.23
Type:
  • number

(constant) NaN :number

The name NaN refers to the special number value NaN ("not a number"). Note that NaN is a number, as specified by is_number. See ECMAScript Specification, Section 4.3.24
Type:
  • number

(constant) undefined :undefined

The name undefined refers to the special value undefined. See also textbook explanation in section 4.1.1.
Type:

Functions

arity(f) → {number}

Returns the number of parameters the given function f expects, excluding the rest parameter.
Parameters:
Name Type Description
f function given function
Returns:
number of parameters f expects
Type
number

char_at(s, i) → {string}

Takes a string s as first argument and a nonnegative integer i as second argument. If i is less than the length of s, this function returns a one-character string that contains the character of s at position i, counting from 0. If i is larger than or equal to the length of s, this function returns undefined.
Parameters:
Name Type Description
s string given string
i number index
Returns:
one-character or undefined
Type
string

display(v, s) → {value}

Optional second argument. If present, displays the given string s, followed by a space character, followed by the value v in the console. If second argument not present, just displays the value v in the console. The notation used for the display of values is consistent with JSON, but also displays undefined, NaN, Infinity, and function objects.
Parameters:
Name Type Description
v value to be displayed
s string to be displayed, preceding v, optional argument
Returns:
v, the first argument value
Type
value

error(v, s)

Optional second argument. If present, displays the given string s, followed by a space character, followed by the value v in the console with error flag. If second argument not present, just displays the value v in the console with error flag. The evaluation of any call of error aborts the running program immediately. The notation used for the display of values is consistent with JSON, but also displays undefined, NaN, Infinity, and function objects.
Parameters:
Name Type Description
v value to be displayed
s string to be displayed, preceding v

get_time() → {number}

Returns number of milliseconds elapsed since January 1, 1970 00:00:00 UTC. See also textbook example.
Returns:
current time in milliseconds
Type
number

is_boolean(v) → {boolean}

checks whether a given value is a boolean
Parameters:
Name Type Description
v value to be checked
Returns:
indicating whether the value is a boolean
Type
boolean

is_function(v) → {boolean}

checks whether a given value is a function
Parameters:
Name Type Description
v value to be checked
Returns:
indicating whether the value is a function
Type
boolean

is_number(v) → {boolean}

checks whether a given value is a number. See also textbook example.
Parameters:
Name Type Description
v value to be checked
Returns:
indicating whether the value is a number
Type
boolean

is_string(v) → {boolean}

checks whether a given value is a string. See also textbook example.
Parameters:
Name Type Description
v value to be checked
Returns:
indicating whether the value is a string
Type
boolean

is_undefined(v) → {boolean}

checks whether a given value is the special value undefined
Parameters:
Name Type Description
v value to be checked
Returns:
indicating whether the value is undefined
Type
boolean

parse_int(s, i) → {number}

Interprets a given string s as an integer, using the positive integer i as radix, and returns the respective value.
Examples: parse_int("909", 10) returns the number 909, and parse_int("-1111", 2) returns the number -15.
See ECMAScript Specification, Section 18.2.5 for details.
Parameters:
Name Type Description
s string string to be converted
i number radix
Returns:
result of conversion
Type
number

prompt(s) → {string}

Pops up a window that displays the string s, provides an input line for the user to enter a text, a Cancel button and an OK button. The call of prompt suspends execution of the program until one of the two buttons is pressed. If the OK button is pressed, prompt returns the entered text as a string. If the Cancel button is pressed, prompt returns a non-string value.
Parameters:
Name Type Description
s string to be displayed in popup
Returns:
entered text
Type
string

stringify(v) → {string}

returns a string that represents the value v, using a notation that is is consistent with JSON, but also displays undefined, NaN, Infinity, and function objects. See also textbook example.
Parameters:
Name Type Description
v value the argument value
Returns:
string representation of v
Type
string