Docly Developers
Function Keyword Updated 23 Oct 2026

function [name], [params]

Declares a function. Functions are closures (they keep access to the variables where they were defined), and parameters can have default values: function f(a = 1) { … }. Arrow functions (x => x * 2) are supported, also nested (a => b => c), and so is spread when calling: f(...args). Inside a function, arguments holds every value it was called with (arguments.length, arguments[0]); an arrow function sees the arguments of the function around it. A function's name and length work as in standard JavaScript.

Not supported in HashJS: rest parameters (function f(...args)) — use arguments instead — and method shorthand in object literals ({ f() }) — write f: function () instead. A named function expression (var g = function h() { … }) cannot refer to itself as h inside its body; use g.

Parameters

namestringoptional

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.

paramsanyoptional

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

Normal JavaScript, 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