Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

102
Views
Confused about promise in javascript

I'm confused about promises. Why does my variable response_status not change, after axios query. How could I change it?

import axios from 'axios/dist/axios.min.js';

function addOrRemoveFavourite(variation_id, isFav) {
    var response_status = true;

    if (typeof variation_id == 'undefined' || typeof isFav == 'undefined') {
        response_status = false;
    } else {
        let data = {
            product_variation: variation_id
        };
        if (isFav) {
            axios.post('/api/product/remove-from-favourite', data).then(response => {
            }).catch((error) => {
                if (error.response) {
                    response_status = false;
                    alert(error.response.data.message);
                }
            });
        } else {
            axios.post('/api/product/add-to-favourite', data).then(response => {
            }).catch((error) => {
                if (error.response) {
                    alert(error.response.data.message);
                    response_status = false;
                }
            });
        }
    }
    return response_status;
}

response = addOrRemoveFavourite(49, true); //always returns true
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!