Home forums Using CanvasJS Can not use variables outside the function Reply To: Can not use variables outside the function



Variable S and A gets value and goes to global scope inside updateChart method, which gets executed after 10ms (based on the value of updateInterval). But you are consoling the values is outside the method – which gets executed first. Consoling S and A after the first execution of updateChart method should work fine in this case.


var updateChart = function () {
    S = 35;
    A = Math.sin(Xa * Math.PI / 180);
}, 1000);

function consoleValues(){
  console.log(S); //Still accessible outside updateChart method

Vishwas R
Team CanvasJS