anything within {...} that is declared (var, let, const) is inaccessible outside the {..}.
This is called scope. Read up on it. It is very important!
Everything you wanted to know about JavaScript scope[
^]
In order to access it outside the scope, you must either declare it outside, or extend an object that has been declared outside (such as scope for example, but this is generally bad practice).
Declare outside scope:
var lastlockerbalance = null;
var getlockerbalance=function(){
$http.get("php/selectLOCKERBALANCE.php")
.success(function(lockerbalance){
$scope.lockerbalance1=lockerbalance;
lastlockerbalance=$scope.lockerbalance1[0].LOCKERBALANCE;
console.log(lastlockerbalance);
})
console.log(lastlockerbalance);
The alt. is to extend an object that is declared outside the scope (pretty much the exact same thing if you understood the scope and dom:
var item = {};
var getlockerbalance=function(){
$http.get("php/selectLOCKERBALANCE.php")
.success(function(lockerbalance){
$scope.lockerbalance1=lockerbalance;
item.lastlockerbalance=$scope.lockerbalance1[0].LOCKERBALANCE;
console.log(lastlockerbalance);
})
console.log(item.lastlockerbalance);
Please don't make a habit of doing the second version. If you do then you should always declare the objects property first:
var item = {lastlockerbalance:null};
or
var $scope.item = {lastlockerbalance:null};
hope that helps
Andy ^_^