I'm working on a piece of legacy code and found a snippet looking like this:
const createError = function(msg) {
return new Error(msg);
};
//...
const error = new createError('Something bad happened');
I see error
actually gets the return value of createError
so it seems that the new
keyword has no effect in this case. But how does it actually work?