8
As mentioned in the title, the resolve and Reject of a Promise already "make paper" of Return or yes (depending on the occasion) I need to use the Return?
Explaining with code, I could do these two ways:
//Retorna os ids dos produtos da aplicação!
function getProducts() {
    return new Promise(function (resolve, reject) {
        fetch("/api/catalog_system/pub/products/search?fq=productId:" + dataLayer[0].productId).then(function (response) {
            return response.json()
        }).then(function (res) {
            if (!res || res.length <= 0) resolve(null)
            else resolve([dataLayer[0].productId, res[0]["Compre Junto"][0]])
        }).catch(function (error) {
            reject(error);
        })
    })
}
//Retorna os ids dos produtos da aplicação!
function getProducts() {
    return new Promise(function (resolve, reject) {
        fetch("/api/catalog_system/pub/products/search?fq=productId:" + dataLayer[0].productId).then(function (response) {
            return response.json()
        }).then(function (res) {
            if (!res || res.length <= 0) return resolve(null)
            else return resolve([dataLayer[0].productId, res[0]["Compre Junto"][0]])
        }).catch(function (error) {
            return reject(error);
        })
    })
}
The two work, however, I don’t know if I should use Return or not, if it would influence anything... Can someone explain?
Thank you!