JavaScript/JXA WARNING! Watch Your "return" Statements Closely!

JavaScript/JXA doesn't care about whitespace in lines, right? For example, you can place a "{" at the end of a line, or at the start of a new line, right?

Try running this:

function test1() {
    return "test1";

function test2() {

console.log("Result of test1: '" + test1() + "'");
console.log("Result of test2: '" + test2() + "'");

If you're running this from Script Editor, you'll need to select the "Messages" tab at the bottom.

1 Like

Perhaps the “return” statement is different.
This works:

function test2() {
    return "a" +


Have you tried this in a pure JavaScript script in a browser?

The thing to learn is the rules of automatic semi-colon insertion:


The issue is if a return statement is on a line by itself, the compiler automatically inserts a semicolon after it. As Rob’s link shows.