Best practice in handling function returns

You can minimize problems that might occur due to differences in how FESI and IBM® JSEngine handle JavaScript. The differences involve implicit return values from functions.

For example, given these statements:

function sumValue() {
  var a = 3;
  var b = 2;
  a + b;
}

With FESI, the function sumValue() returns 5 because 5 is the result of the last statement run in the function. Using IBM JSEngine, the expression sumValue() returns null because there is no explicit return. The correct code for IBM JSEngine includes an explicit return statement:

function sumValue() {
  var a = 3;
  var b = 2;
  return a + b;
}

To keep JavaScript code consistent, always use an explicit return value in functions. In the previous release, some of the service selection script examples did not use an explicit return value. Update any JavaScript code that is based on these examples to have an explicit return value, to ensure that the code continues to work after an upgrade to use IBM JSEngine.