In JavaScript, new is a syntactic sugar that simplifies the code writing and allows for the batch creation of object instances.
Syntactic sugar refers to a certain syntax added to a computer language, which does not affect the language's functionality, but makes it more convenient for programmers to use. Generally, the use of syntactic sugar can increase the readability of the program and thus reduce the chance of coding errors.
Suppose we don't use new to initialize and create 10 student object instances.
var stuGroup =[];for(let i=0;i<10;++i){var obj ={name: i,hp:100,mp:1000,power:100,defense:100} stuGroup.push(obj);}console.log(stuGroup);
At this point, we will obtain 10 initialized student object instances. However, using the new keyword can simplify the operation, and we can also use the prototype chain to share properties and other operations.