Why the chat-gpt cannot calculate the correct result of the rcursion of a closure function in a currying using Javascript?

  Kiến thức lập trình

There has a problem between chat-gpt and me. That is, I instruct the chat-gpt to calculate the output of the following javascript code, the correct answer of the this code is 243 but chat-gpt says me the actual answer if 60. Somome can explain the actual fact fro why chat-gpt can’t produce the correct answer. Code is following :

const h = (a) => {
  const g = (b) => {
    if (b <= 1) {
      return a;
    } else {
      return a * g(b - 1);
  return g;

const f = (a) => h(a);
const c = f(3);

I tried to trace the control-flow of the code. I expect for the actual control flow of this code. I thinks there has some issue in this code not formally.

New contributor

Min Thuta Shein Thuta is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.