Understanding the new Keyword in JavaScript — A Tea Shop Analogy
If you are ever wondered what the new keyword does in javascript, let’s skip the jargon and step into a place we all know — a local tea shop.
Yes, we’re about to understand JavaScript by brewing tea. 🍵
🧠 What Is the new Keyword?
In JavaScript, the new keyword is used to create a new instance of an object using a constructor function.
Think of it as asking a machine to make something for you, like a fresh cup of tea.
🫖 Welcome to the JavaScript Tea Shop
Imagine you’re running a tea shop. You’ve got a machine that makes different types of tea based on customer preferences.
Let’s create that machine in code:
function Tea(type, sugarLevel){
this.type = type;
this.sugarLevel = sugarLevel;
}This function is like your tea making machine, when you pass in the type of tea and sugar level , it will prepares a customized tea for your customer.
Now, you use new whenever a customer orders:
const ramTea = new Tea("Ginger", "Less Sugar");
const sitaTea = new Tea("Cardamom", "No Sugar");What Really Happens When new Tea() is Called:
1. A new empty cup (object) is created
2. The tea machine (Tea function) prepares the tea and fills the cup
Get Ram’s stories in your inbox
Join Medium for free to get updates from this writer.
3. You get your custom cup of tea as a result
console.log(ramTea);
// Output: { type: "Ginger", sugarLevel: "Less Sugar" }
console.log(sitaTea);
// Output: { type: "Cardamom", sugarLevel: "No Sugar" }What if You Forget new?
const wrongTea = Tea("Masala", "More Sugar");
console.log(wrongTea); // ❌ undefinedWhy? Because you didn’t use the tea machine correctly, so the tea wasn’t returned to your hands.
Real-Life Example — A Tea Seller
Let’s take it one step further:
function Person(name, work) {
this.name = name;
this.work = work;
}
const teaSeller = new Person("Ramu", "Tea Shop Owner");
console.log(teaSeller);Output:
{ name: "Ramu", work: "Tea Shop Owner" }🧵 Summary
• function Tea(…) is the tea-making machine.
• new Tea(…) creates a new customized cup of tea.
• Each call with new gives you a fresh object.
- Forgetting new means your tea isn’t made properly!
Final Words
If you’re just starting with JavaScript and object-oriented programming feels intimidating — remember the tea shop.
Every new object is just another customer’s cup.
Would you like a follow-up on class, this, or prototype explained the same way? Let me know in the comments.
🖊️ Written by: Ram
JavaScript Learner | Tea Lover | Medium Explorer







