JSFiddle - React, Tailwind, and code Playground

by JimmyJoe12378

JavaScript

function updateTestVariable(key, callback) {
  console.log("2 ENTERupdateTestVariable key is: " + key);
  callback(key)
}

var testVariable = ""

console.log("1 BEFORE updateTestVariable is called testVariable is " + testVariable)

updateTestVariable("VARIABLE HAS UPDATED", async function(firstParam){
  console.log("3 ENTER updateTestVariable firstParam is: " + firstParam);
  console.log("4 text before timeout starts testVariable is: " + testVariable)
  
  var mockingAsyncServiceCall = await setTimeout(() => {
          testVariable  = firstParam
          console.log("5 AFTER TIMEOUT COMPLETE  testVariable is " + testVariable)
        }, 4000);

console.log("6 line after timeout, testVariable is " + testVariable)
})

console.log("7 AFTER updateTestVariable is called testVariable is " + testVariable)