JSFiddle - React, Tailwind, and code Playground

JavaScript

let closedVariable = 0;

const intervalFn = () => {
	return setInterval(() => {
  	setClosedVariable(closedVariable + 1)
    console.log(closedVariable)
  }, 1000)
}

function setClosedVariable(num) {
	return closedVariable = num
}

intervalFn();

// prints incremented closed variable as expected
// closedVariable is correctly updated