For example:
var obj = {};
$.getJSON('data.json', function(data) {
obj = data;
});
console.log(obj)
The console then outputs an empty object instead of whatever value data
was.
For example:
var obj = {};
$.getJSON('data.json', function(data) {
obj = data;
});
console.log(obj)
The console then outputs an empty object instead of whatever value data
was.
in your code
$.getJSON('data.json', function(data) {
obj = data;
});
is an asynchronous function, the code
console.log(obj)
does not wait for it to stop executing and hence you cannot see anything