0

Hi there i have followed code, but i don't get returned data outside function.

function get() {
    $.get( 'data.json', function( d ) {
        return d;
    }).fail(function() {
        console.log('err');
    });
}

console.log(get());

output: undefined

Thanks for your helps.

Jeremy
  • 88
  • 7

1 Answers1

0

This is asynchronous Js

function get() {
    return $.get( 'data.json', function( d ) {
        return d;
    }).fail(function() {
        console.log('err');
    });
}

get().then((data)=>console.log(data))
Oleksandr Poshtaruk
  • 2,062
  • 15
  • 18