It is possible to use JS native code on client functions and Java code on Server functions.
Block var i declares a function-scoped variable, initializing it to a value.
It is possible to rename such variables and set or get their values, too.
Return statement is specified at the end of a function call and returns a value from a function. You should also specify the proper return type to avoid compilation errors.
Calling functions with return have the following syntax:
Native code block allows you to write the language’s code directly inside the block. Here we have a server function and the native code will be considered as Java code.
In the example below we created a boolean variable enough_food, and then inside native code block we have a list of Strings and one IF operator that can change the var enough_food from above. And we get the info message “i can have breakfast: false”.
Try - catch - finally
Try - The statements to be executed. In the example below, we have a Zero Division Error, so we should catch it.
Catch - Statement that is executed if an exception is thrown in the try-block. You can add an exception after clicking the gear icon on the top of the try block.
Exception variable (e - can be renamed) - an optional identifier to hold an exception object for the associated catch-block. You can find the list of java exceptions here.
To add an exception object, use a custom type from the TYPE section and give the name of an exception that should be caught.
It’s a good practice to show some error info.
It is possible to log original error message using Native code block. exceptionVarName.getMessage() allows you to do this.
Finally - holds statements that are executed after the try statement completes. These statements execute regardless of whether an exception was thrown or caught. You can drag and drop the finally statement after clicking on the gear icon of the try-block
Block function acts like an arrow function in JS.
The code below declares a lambda function to get a string and then calls it from native code.
A comment is a programmer-readable explanation in the source code. They are added with the purpose of making the source code easier for humans to understand, and are ignored by compilers and interpreters
Cast to type
Type casting is when you assign a value of one primitive data type to another type.