JSFiddle - React, Tailwind, and code Playground

JavaScript

var str = 'chupacabra';

function reverse(str) {
	if (str.length === 0) return '';
  
	var
  	s1 = str[0],
    s = str.slice(1, str.length - 1),
    s2 = str[str.length - 1]
    
  return s2 + reverse(s) + s1
}

console.log(reverse(str))