Google’s Gary Illyes stated on twitter that it is probably not a good idea to use JavaScript redirects. This was particularly to redirect users based on their location to a country-specific version of the page. But to know Google had said earlier that server-side redirects are the best.
Gary Illyes Tweet
Js redirects are probably not a good idea though.
— Gary 鯨理/경리 Illyes (@methode) July 8, 2020
Recommendation: Google Announces New Swirl 3D Ad Option For Display Video 360 Campaigns
Google John Mueller Statement Back In 2016 On Google+
JavaScript redirects: If you can’t do a server-side redirect, using JavaScript is a good fall-back. If you’re using a JavaScript framework for your site, this might also be the only option. Caching depends on the server settings, and search engines have to guess at what you’re trying to do (index under R or S?).”
Go server-side when implementing redirects.