In javascript, one is used to either do callbacks or return promises for async functions... I was just wondering, how does this work with the parameters inside the callbacks or promises, I mean one often sees things like this:
function (error, response, body) {..}
Is the order of callback arguments defined here? Or otherwise said: Does javascript somehow "know" about what an "error" parameter and anything else is? Are there reserved keywords in javascript for e.g "error | err | e", etc.?
e.g I have seen this code here:
const bcrypt = require('bcrypt');
const password = 'Top Secret';
bcrypt.hash(password, 10, (err, hash) => {
if (err) {
throw err;
}
console.log('Your hash: ', hash);
});
Where "err" is first argument, the data is second, but then:
bcrypt.hash(password, 10).then(
hash => {
console.log('Your hash: ', hash);
},
err => {
console.log(err);
}
);
Where apparently hash is first argument in the promise, and err is second parameter, so my question is: How does javascript in general know what the error and other arguments are? Are there docs or guidelines about that?