Hi there! So the JS code is a little tricky here. Every external function, in this case .trigger and .setValue, happens asynchronously together at the end of the JS query using the values that are defined at that point internally in the JS code. So what is happening here is:
Query runs, evaluates textOutput.value
Query completes
textOutput’s value is set to ‘Init:’
myQuery is run, with an onSuccess function that is defined using the original value of textOutput.value
textOutput’s value is set to that textOutput.value property, with the data +='ed to it.
To put it another way, here’s what you could expect from this code section:
let val = tempState.value;
console.log(val); //returns "Original Value"
tempState.setValue("Hello!");
console.log(tempState.value); //returns "Original Value"
-----code ends----
//In the browser console you'll see
Setting value of tempState to "Hello!"
In this specific example, it doesn’t actually seem like the original value of the textOutput matters? If so, something simple like this would work but I feel like I’m missing the overall goal here: