new Operator
noun
say it: “NOO OP-er-ay-ter” /nuː ˈɒpəreɪtər/
The keyword new, which builds a fresh object from a class, runs the class's constructor and hands the object back.
What is new Operator in JavaScript?
new Operator — The new keyword in front of a class name. It makes a fresh object, runs the class's constructor to give it its starting values, and hands the object back. Calling a class without new stops with a TypeError.
class Ship {
constructor(name) {
this.name = name;
}
}
const vega = new Ship('Vega');
console.log(vega.name); // Vega
In a sentence
- “Leaving new off in front of Ship("Falcon") gave me a TypeError instead of a ship.”
Level: Apprentice · More JavaScript terms at this level
Updated