function [name], [params] Last updated: 06. Mar 2023

Keyword

Keyword that declares a function.

Parameters

Name Type Description
name (optional) string Name of function, if not specified only a reference to the function will be generated.
This can be stored in a variable or in a struct.
params (optional) any Define one or many params you want to use in your function.

Returns

The function keyword returns a callable function if no name is given. Your function will return whatever you return with the "return" keyword, from within your function body.

Example

Code example (JS)

JS is normal JavaScript either running in the browser or on the Docly™ server.
function myFunc(a, b) {
    return a + b;
}

write(myFunc(1, 2)); // Outputs 3

let mystruct = {
  "func1" : function (a, b) { return a - b; }
};

write("\r\r"); // Insert some new lines between output
write(mystruct.func1(1, 2)); // Outputs -1

Output

The JS code above produces the output shown below:
3

-1