I
I
Ivan2021-01-10 18:44:36
Node.js
Ivan, 2021-01-10 18:44:36

Why doesn't the outer variable change?

const scra = require('scra');

function main(message) {
    var rating;
    var getRating = (data) => {
        rating = data;
    }
    scra('тут сайт, данные которого я успешно получаю', (err, res) => {
        if(err) console.error(err.message);
        if(res) rating = JSON.parse(res.body);
        getRating(rating);
    });
    console.log(rating);
}

main("fff");

ratingHow can I assign the received value to an external variable in scra? I tried to change directly, but a new local variable is created and the callback function is used

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question