What is the difference between the following two statements?
Statement 1:
throw Error("some error message");
Statement 2:
throw new Error("some error message");
JavaScript sets 'this' to the global environment by default for calling it like an ordinary function, so it works but your global 'this' object is messed up, when u call the constructor function with new keyword it will create a new 'this' object and will return that with the properties and methods in it.
Luiz Filipe da Silva
Brazilian full stack developer, tale writer, and aspiring computer scientist.
Basically,
newinstantiates new objects.Error, in your example, is an entity only, while you intend to generate an object using the skeleton that the entity provides. This new object will contain all the references present within theErrorentity, but always pointing to it.