Javascript node code question

Hey,

So this is basically some JS help question, since I’m still getting the hang of it + Noodl.

My code looks something like this (I’m skipping the functional part to get to the problem):

var avg = ...;
function approx(inputAverage, newValue) {
    return value
}

define({
    inputs: {
    ...
    },
outputs: {
    ....
},
setup: function(inputs, outputs) {
    // no code here
},
run: function(inputs, outputs) {
        avg = approx(avg, inputs.someVariable);
        outputs.someVariable = avg;
}

});

The code above works only if I Open and then Close the JS node inside Noodl, otherwise I’m getting the output at NULL on the output. I’m pretty sure that I’m not initializing avg in the right place or have to do something like this.avg somewhere :slight_smile: Not sure where exactly… This is the part that’s tripping me with Noodl, since I’m not getting the mental model how a JS node is constructed and construct functions / variables inside of it.

Thanks again!