Snowed In
Snowed In

Reputation: 1

Simple script in acrobat debugger SyntaxError: missing ; before statement

I'm new to Acrobat javascript and am working out how to use the debugger. I entered the following in the console. It ran fine the first time. However, now I'm getting missing ; before statement error. This is what I'm trying to run and the message I'm getting:

let myNameArray = [('Chris','Jim','Marie','Stacy')];
let myNumArray = [10, 20, 25, 30];
myNameArray[2];
myNumArray[1];
        
SyntaxError: missing ; before statement
1:Console:Exec
undefined

Am I missing something that has to do with the debugger?

I pared down the script to this:

let myNameArray = ['Chris', 'Jim', 'Marie', 'Stacy');
myNameArray = [0];

This script returned Chris.

I then added myNumArray code as above and it worked. The only thing I did differently was to close all of my Acrobat windows and start from the beginning. It's confusing to me.

Upvotes: 0

Views: 647

Answers (2)

joelgeraci
joelgeraci

Reputation: 4917

The Acrobat JavaScript interpreter doesn't support "let".

Use...

var myNameArray = ['Chris', 'Jim', 'Marie', 'Stacy'];
var myNumArray = [10, 20, 25, 30];

Upvotes: 1

epascarello
epascarello

Reputation: 207501

When your code runs you are basically getting the following

let myNameArray = ['Stacy'];
let myNumArray = 30; 

The reason why is the comma operator. When you wrap the code in () you all of the sudden have a comma operator. The comma operator , evaluates each of its operands (from left to right) and returns the value of the last operand.

const myNameArray = ['Chris', 'Jim', 'Marie', 'Stacy'];
const myNumArray = [10, 20, 25, 30];
console.log(myNameArray[2]);
console.log(myNumArray[1]);

Upvotes: 0

Related Questions