1

I've code like this:

var isPushEnabled;

OneSignal.isPushNotificationsEnabled(function(response) {
    if (response) {
        isPushEnabled = true;
        console.log(isPushEnabled); // it shows true
    } else {
        isPushEnabled = false;
        console.log(isPushEnabled); // it shows false
    }
});

console.log(isPushEnabled); // it shows undefined

I'm looking for a way to show "true" or "false" instead of "undefined" in the last stage.

Thanks in advance for reply!

toch
  • 9
  • 2
  • So probably the callback is not called before you log the `undefined` value? – Bergi Mar 26 '18 at 20:27
  • just wild idea, why don't u define it as boolean type? – Kick Buttowski Mar 26 '18 at 20:28
  • "_I'm looking for a way to show "true" or "false" instead of "undefined" in the last stage._" You can just give the variable a default value `var isPushEnabled = false;`, but that's probably not what you want. The problem is that the line of code you are asking about executes before your callback. – takendarkk Mar 26 '18 at 20:29

0 Answers0