Cannot string-slice a loop variable (or an image path)

I have a loop in which a different image object (image_for_eval) is shown in each iteration. The image path is taken from an excel using a variable ($evaluate_fname).
Later in the loop, I try to extract a string slice from this variable ($evaluate_name) or from the image path (image_for_eval.image) which should be the same.

I get an error “TypeError: slice is not a function”.

Interestingly, the slice function works with the same variable when it is thrown in an exception.

Here’s the Javascript code that throws an error with the correct slice (an oxymoron):

s = evaluate_fname;
try {
    sliced = s.slice(-6,-3);
} catch(e) {
    throw new Error(s.slice(-6,-3));