#does var not work inside of a .then

11 messages · Page 1 of 1 (latest)

supple burrow

it should but you shouldn't be using var anymore, use let or const

then why are you redeclaring it using var inside the then

you can overwrite variables declared with let

why would i lie

let somevar = ""

somepromise().then(() => {
  somevar = "something else"
})

declare it first, do not redeclare it

and declare it on the same scope or one scope higher than where you need it

velvet kraken

Thats... not the right solution either

When you try to access somevar its still going to be empty because the .then hasnt executed yet

You need to learn how to handle promises correctly

supple burrow

thats very true