Write a program to convert a binary number to decimal number using recursion

Converting binary numbers to decimal numbers is a little tricky. The base of binary numbers is 2. The following code segment converts a binary number to a string.

(function(){
    // Write a program to convert a binary number to a decimal number using recursion

    const getDecimal = (n) => {
        if (!n) {
            return 0;
        } 
        return  n[0] * (2 ** (n.length - 1)) + getDecimal(n.slice(1))
    };
 
    console.log(getDecimal('111')) // 7
})();