0
I have a problem and I don’t know how to solve it, I’m new in javascript and I can’t change a value of an external variable within an internal function of . then:
var DadosCadastrados = function(){
var dados = 1;
User.findAll().then(cads => {
dados = 2;
}).catch(erro =>{
dados = 3
})
console.log(dados)
return dados
}
data is still printed as 1 and not as 2. how do I change its value? (Obs: the function then is being called and I put a console.log(data) inside then and it returns 2, but it returns 1 again)
The variable given = 1 is in the Globa scope and the others are inside an Arow Function, the variables inside a function are not visible outside the function. Therefore, the.log console will return the variable from outside the function.
– user172788