惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

U
Unit 42
Blog — PlanetScale
Blog — PlanetScale
H
Help Net Security
The GitHub Blog
The GitHub Blog
博客园 - Franky
酷 壳 – CoolShell
酷 壳 – CoolShell
Recent Announcements
Recent Announcements
量子位
aimingoo的专栏
aimingoo的专栏
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
Microsoft Azure Blog
Microsoft Azure Blog
Martin Fowler
Martin Fowler
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
A
About on SuperTechFans
T
Tailwind CSS Blog
V
V2EX
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
B
Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
S
SegmentFault 最新的问题
G
Google Developers Blog
M
MIT News - Artificial intelligence

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Abstraction in JavaScript — Explained in Simple Words (an...
SAURAV KUMAR · 2026-04-22 · via DEV Community

If you are learning Object-Oriented Programming (OOP) in JavaScript, one word that can feel scary is: Abstraction.

When I started learning it, I thought it was some complex math or high-level theory. But I was wrong. The idea is actually very simple.

In this post, let’s understand abstraction in very simple words, step by step, using JavaScript.


🧱 What is Abstraction?

In simple words, abstraction means:
Hiding the messy internal logic and showing only what is needed.

Think of it like this:

  • Abstraction is about what an object does.
  • Implementation is about how it does it.

You focus on the "what" and hide the "how."


🚗 The "Car" Analogy

Think about driving a car. You only care about:

  • The steering wheel
  • The brake
  • The accelerator

You do not care about how the fuel moves into the engine or how the pistons are firing. That is all hidden from you.

That is abstraction. The car gives you a simple interface (the pedals and wheel) so you don't have to worry about the complex engine.


⚙️ Abstraction in JavaScript

In JavaScript, we don't have an abstract keyword like Java. So, we achieve abstraction by designing our classes carefully.

We do this by:

  1. Creating simple public methods.
  2. Hiding the "helper" steps inside the class.

☕ Example: The Coffee Machine

Let’s see it in code:

class CoffeeMachine {
  // This is the only thing the user needs to know
  makeCoffee() {
    this.#boilWater();
    this.#addCoffeePowder();
    this.#pourIntoCup();
    console.log("Your coffee is ready! ☕");
  }

  // These are internal steps (hidden from the user)
  #boilWater() {
    console.log("Boiling water...");
  }

  #addCoffeePowder() {
    console.log("Adding coffee...");
  }

  #pourIntoCup() {
    console.log("Pouring into cup...");
  }
}

const myMachine = new CoffeeMachine();
myMachine.makeCoffee();

Enter fullscreen mode Exit fullscreen mode

Why is this good?

The user only calls makeCoffee(). They don't have to worry about the order of boiling water or adding powder. The complexity is abstracted away.


🔍 Abstraction vs Encapsulation

Many beginners mix these two up. Here is the easiest way to remember the difference:

  • Abstraction: Focuses on simplicity. It asks: "What should the user see?" (Hiding complexity).
  • Encapsulation: Focuses on safety. It asks: "How do we protect the data?" (Hiding state).

The Bank Analogy:

  • Abstraction: You use the ATM screen to "Withdraw Money." You don't see the bank's internal database logic.
  • Encapsulation: Your accountBalance is private. You can't change it directly; you must use a deposit() method that checks if your ID is valid first.

❌ Common Beginner Mistakes

  1. Over-abstracting: Don't hide everything. If a user needs to control something, give them a method for it.
  2. Mixing the two: Remember, hiding a function to make code cleaner is Abstraction. Hiding a variable to prevent bugs is Encapsulation.
  3. Thinking it's just for big apps: You can use abstraction even in small 50-line scripts to make them easier to read!

🎯 Interview-Friendly Recap

If an interviewer asks, "What is Abstraction?", say this:

"Abstraction is hiding the internal implementation details of a system and showing only the essential features to the user. It reduces complexity and makes the code easier to maintain."


✅ Final Thoughts

Abstraction is not about being "fancy." It’s about being kind to your future self (and other developers).

By hiding the messy parts of your code, you make your objects easier to use and much harder to break.

Start thinking about your classes like a "Black Box"—give them a simple input, get a simple output, and keep the "magic" hidden inside.


🙋‍♂️ About Me

Hi, I’m Saurav Kumar.

I enjoy learning, building, and writing about web development in simple words—especially breaking down topics that are useful for beginners and developers preparing for interviews.

Right now, I’m focusing on deepening my understanding of core concepts like JavaScript, OOP, system design, and software engineering fundamentals.

Let's connect!