🧠 What does new do in JavaScript?

The new keyword is used to create a new instance of an object or class.
When you write:
const scene = new Scene(engine);
You are telling JavaScript:
“Hey, create a new Scene object, and use the Scene constructor function to set it up.”
.
🔍 Why do we need new here?
Because FreeCamera, Vector3, and Scene are all constructor functions (or classes) in Babylon.js.
Using new:
• Allocates memory for the new object
• Runs the constructor
• Sets up the object’s internal properties
🔧 Analogy:
const car = new Car(); // You just built a new car.
Without new, you’re just calling a function, not building an object — which often leads to errors or undefined behavior.
✅ Summary:
Keyword | Purpose |
new | Creates a new instance of a class/object |
Without new | Constructor won’t work properly (or at all) |
Let me know if you want a breakdown of how constructors work under the hood or how to make your own class using new!
Subscribe to my newsletter
Read articles from Godson Prakasia directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
