[1.6.x] Fixed #21347 -- Added missing JS variable declaration.

Thanks szymon.barglowski at gmail.com for the report.

Backport of 0b1d425a41 from master