It seems like I can't access variable outside a function if globally defined.
var test;
function foo() {
$.ajax({
url: '[MY LINK]',
dataType: 'json',
type: 'get',
cache: false,
success: function(data) {
$(data.feeds).each(function(index, value) {
var value = parseFloat(value.field1);
test = 10;
});
}
});
}
console.log(test)
What I see in my console is:
undefined
I've tried not to declare the variable into global scope but that way it returns an error:
Uncaught ReferenceError: test is not defined at index.js:80
According to what I read on the web not writing "var" for a variable makes it globally available.