Reputation: 2455
document.getElementById('button').addEventListener('click', function() {
ApiCall()
console.log(lol)
});
function ApiCall() {
var lol = "this is a test";
}
I have looked into the javascript scopes but how would i pass this variable to the first function ?
Upvotes: 0
Views: 35
Reputation: 92440
You should return the value from your function. Like this:
document.getElementById('button').addEventListener('click', function() {
var passed_lol = ApiCall()
console.log(passed_lol)
});
function ApiCall() {
var lol = "this is a test"
return lol;
}
<input id="button" type="button" onclick=stop() value="clickme">
Upvotes: 2