If programmers of functional languages were better at naming things, it would be easy. Let's rename g to callTwice and h to aFunction:
function callTwice(aFunction) {
return function(y) {
return aFunction(aFunction(y));
};
}
function square(x) { return x*x; }
var squareTwice = callTwice(square);
81 === squareTwice(3);