Weird Uncaught ReferenceError in JavaScript

I am getting the following error:

Uncaught ReferenceError: oldId is not defined

On this line:

oldId = this.target.dataset.widgetId + "-" + (this.carousel.prevPage + 1);

That error makes no sense to me. I am defining oldId in that line.