0

I Want to access variable from doinit to saveexpenses method. I am trying to access temp variable in saveExpense. The console is throwing undefined

 ({
 doInit: function(component, event, helper) {
    helper.getMatrix(component, event);
    helper.getRolesConverted(component, event);
    var temp=0;
},
saveExpenses: function(component, event, helper) {
     helper.saveExpenses(component, event);
     console.log('temp value ',temp);
},
});
Gajini
  • 413
  • 1
  • 5
  • 21
  • 1
    ...And? Have you tried accessing it, maybe passing it to a function call? – Luca Kiebel May 03 '18 at 10:06
  • it is throwing as undefined – Gajini May 03 '18 at 10:07
  • Which variable are you trying to access? Please update your question to indicate what you have tried, the expected behaviour and the actual error behaviour (this will help us have better context to answer the question) – Chirag Ravindra May 03 '18 at 10:08
  • 1
    Possible duplicate of [Accessing variables from other functions without using global variables](https://stackoverflow.com/questions/407048/accessing-variables-from-other-functions-without-using-global-variables) – Red Bottle May 03 '18 at 10:08
  • make it a global variable for the file? pass it as a parameter? – mast3rd3mon May 03 '18 at 10:12

1 Answers1

0
var temp;
({
 doInit: function(component, event, helper) {
    helper.getMatrix(component, event);
    helper.getRolesConverted(component, event);
    temp=0;
},
saveExpenses: function(component, event, helper) {
     helper.saveExpenses(component, event);
     console.log('temp value ',temp);
},
});
SMH
  • 889
  • 3
  • 11
  • 30