About JavaScript
This section provides a basic explanation of how the language works:
Variables
Comments
Arrays
Operators
Conditional Statements
Loops and Iterations
Exception Handling
Variables
Comments
Arrays
Operators
Conditional Statements
Functions
Loops and Iterations
Exception Handling
Recommendations
Explore
Mirth® Connect by NextGen Healthcare User Guide
Conditional Statements
This example shows the basic syntax structure for conditional statements in JavaScript: if (condition1) { // Code to execute} else if (condition2) { // Code to execute} else { // Code to execute} Parent topic: About JavaScript
Mirth® Connect by NextGen Healthcare User Guide
Loops and Iterations
A loop is a type of programming-language statement that lets code be executed repeatedly; that is, a loop is a series of iterations. In programming language, there are four types of loops: for loops for each…in loops while loops do…while loops An iteration is a single execution of the inner loop process. If you loop from 1 to 10, the code inside the loop will be executed for 10 iterations. Loops can be unconditionally exited with a break statement: break;. The continue statement: continue; unconditionally skips to the next iteration of the loop. for loops for each…in loops while loops do…while loops Parent topic: About JavaScript
Mirth® Connect by NextGen Healthcare User Guide
Exception Handling
The variable in a catch statement is of the Error type or one of its subclasses. You can raise exceptions with a throw statement: throw "This is my exception message!"; throw new RangeError("Var x is not between 1 and 100"); Uncaught exceptions inside a connector result in an error status for the processed message. Syntax (Exception Handling) Example try { // Code to execute} catch (exception) { // Exception handling // code to execute} finally { // Code to always execute} try { var x = undefinedVarName;} catch (e) { logger.error("Error: "+e);} Parent topic: About JavaScript
Mirth® Connect by NextGen Healthcare User Guide
Variables
Unassigned variables have the value undefined by default; string literals can use single or double quotes; braces { } create a block of statements that can be used for loops, conditionals, and statements. These are some examples of variable declarations: var x;var y = r;z = "abc" Parent topic: About JavaScript
Mirth® Connect by NextGen Healthcare User Guide
Operators
The most common JavaScript operators can be put into the following categories: Arithmetic Operators Assignment Operators Comparison Operators Logical Operators Arithmetic Operators Assignment Operators Comparison Operators Logical Operators Parent topic: About JavaScript
Mirth® Connect by NextGen Healthcare User Guide
Arrays
Arrays are native objects indexed with bracket notation that can contain other objects, arrays, or primitive types. Arrays can be initialized using Java-like constructors or bracket notation and do not need to be sized upon construction:var myArray1 = new Array(10);var myArray2 = new Array(5, "some string", new Array());var myArray3 = [];var myArray4 = [ "one", "two", "three" ]; Uninitialized elements in arrays are undefined, so use the length property (var size = myArray.length;) to get a size. Use the delete operator to remove the index value, which sets the element as undefined. There are several built-in methods for arrays: concat(), reverse(), replace(), sort(), indexOf(). Arrays in JavaScript are zero-based indexed, so use myArray[0] to access the first element. Other important native objects in JavaScript include: String Date Boolean RegExp (regular expressions) Math XML Parent topic: About JavaScript