Cannot make any script work (solved)

Hi, I'm using the latest version of Advanced Rename and I need to use a script.
For now I simply cannot make any script work.
When I type exactly what is shown in:
https://www.advancedrenamer.com/user_guide/v4/method_script
it doesn't work.
______________________________

When I type:
***
odd = !odd;
var val = (odd) ? 'a' : 'b';
return item.newName + '_' + val;
***
I get SyntaxError: return not in a function
______________________________

Let's try to retype the function name:
***
function(index, item) {
odd = !odd;
var val = (odd) ? 'a' : 'b';
return item.newName + '_' + val;
}
***
same error.
______________________________

Let's get to se simplest function possible:
***
return item.newName;
***
same error.
______________________________

Let's get is simpler:
***
item.filename
***
ReferenceError: item is not defined
______________________________

Please could you hemp me to get anything to work?
Then I will enjoy some JS.

Thank you for any help you may give me.
Reply to #1:
Did you accidentally put your script into the "Pre batch script" window? Because that will cause such error.
Reply to #2:
Thank you very much Kim it's much better.
So global variables can be declared into the "Pre batch script" section. I get it !
Let's enjoy JS now !