Answer the question
In order to leave comments, you need to log in
Why doesn't Return JS work?
Why is there no access to the variable ?
<script>
navigator.getBattery().then(function(battery) {
level = battery.level * 100;
return level;
});
alert(level);
</script>
Answer the question
In order to leave comments, you need to log in
Because you don't know how return works and what asynchronous events are.
At the moment when you call alert, the promise has not yet been fulfilled.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question