I'm a new user of Promises in JavaScript and I have the following code snippet:
const arrayToTest;
let c = seasonalityService.getAnalysis(site, key)
.then(function (result) {
let date = moment();
console.log(result.heating.getSeasonMonths(date));
arrayToTest = result.heating.getSeasonMonths(date);
console.log(result.cooling.getSeasonMonths(date));
})
, function (error) {
console.error('an error occured!!!', error);
};
I have aService.js where I have getAnalysis
method:
aService.getAnalysis = function (site, key) {
return Promise.all([
aService.heat(site, key),
aService.cool(site, key)
]).spread(function (heating, cooling) {
return { heating: heating, cooling: cooling };
});
};
I tested the first part in similar situation and it worked fine but now before I pile the code if I hover over function (error)
it says [js] Variable declaration expected.
I don't understand what variable does it need.
I'm a new user of Promises in JavaScript and I have the following code snippet:
const arrayToTest;
let c = seasonalityService.getAnalysis(site, key)
.then(function (result) {
let date = moment();
console.log(result.heating.getSeasonMonths(date));
arrayToTest = result.heating.getSeasonMonths(date);
console.log(result.cooling.getSeasonMonths(date));
})
, function (error) {
console.error('an error occured!!!', error);
};
I have aService.js where I have getAnalysis
method:
aService.getAnalysis = function (site, key) {
return Promise.all([
aService.heat(site, key),
aService.cool(site, key)
]).spread(function (heating, cooling) {
return { heating: heating, cooling: cooling };
});
};
I tested the first part in similar situation and it worked fine but now before I pile the code if I hover over function (error)
it says [js] Variable declaration expected.
I don't understand what variable does it need.
Share Improve this question edited Apr 21, 2017 at 12:32 Samurai Jack asked Apr 20, 2017 at 9:17 Samurai JackSamurai Jack 3,1359 gold badges36 silver badges59 bronze badges 3- voted to close because it's a simply typographical error – Alnitak Commented Apr 20, 2017 at 9:28
-
1
})
->}
and};
->});
– Jaromanda X Commented Apr 20, 2017 at 9:53 -
1
const arrayToTest;
without an initialiser expression is a syntax error. – Bergi Commented Apr 21, 2017 at 12:53
2 Answers
Reset to default 3The message appears to relate to const arrayToTest;
, which is illegal.
A const
must be initialised at the point of declaration.
Read about const
here.
You have
})
, function (error) {
instead of
}
, function (error) {