JSFiddle - React, Tailwind, and code Playground

JavaScript

//source
function balls(a,b) {
    n=m=r=1;
    for (i=b;i>0;n*=-1) {
        r+=n*m*Math.pow(i,a);
        m=m*i/(b-i--+1);
    }
    return --r;
}

w=function(msg){document.writeln(msg.toString())};

// validate source
w('<pre>');
w(balls(6,3));
w(balls(12,4));
w('</pre>');

//code-golfed
function f(a,b){n=m=r=1;for(i=b;i>0;n*=-1){r+=n*m*Math.pow(i,a);m=m*i/(b-i--+1)}return--r}

// validate code-golfed
w('<pre>');
w(f(6,3));
w(f(12,4));
w('</pre>');