FlareStart
HomeNewsHow ToSources
FlareStart

Where developers start their day. All the tech news & tutorials that matter, in one place.

Quick Links

  • Home
  • News
  • Tutorials
  • Sources
  • Privacy Policy

Connect

Β© 2026 FlareStart. All rights reserved.

Back to articles
πŸ” JavaScript Closures Explained with a Bank Account (Beginners, This One's for You!)
How-ToWeb Development

πŸ” JavaScript Closures Explained with a Bank Account (Beginners, This One's for You!)

via Dev.to WebdevDHANRAJ S3h ago

Ever wondered how a bank keeps your balance private β€” so no one else can just walk in and change it? That's exactly what a closure does in JavaScript. It locks your data away and only lets you touch it through specific actions β€” like a deposit or withdrawal. Let's break it down with a real banking example. 🏦 1. What Is a Closure? Imagine you open a bank account. The bank creates a private locker for you β€” your balance, your account number. No one else can access it directly. You can only interact with it through the bank's services: deposit, withdraw, check balance. In JavaScript, a closure is when an inner function "remembers" the variables from the outer function β€” even after the outer function has finished running. That's it. That's the whole idea. πŸŽ‰ 2. What Does the Code Look Like? Here's the full createAccount function we'll be working with: function createAccount ( userName , initialBalance ) { let balance = initialBalance ; // private let accountNumber = Math . floor ( Math . ra

Continue reading on Dev.to Webdev

Opens in a new tab

Read Full Article
0 views

Related Articles

How-To

Building a Runtime with QuickJS

Lobsters β€’ 1h ago

I can't stop talking about the Ninja Creami Swirl - and it's on sale at Amazon right now
How-To

I can't stop talking about the Ninja Creami Swirl - and it's on sale at Amazon right now

ZDNet β€’ 2h ago

How-To

Do Beginners Still SearchΒ "How to Code"?

Medium Programming β€’ 2h ago

How to Become a Software Developer After 12th?
How-To

How to Become a Software Developer After 12th?

Medium Programming β€’ 3h ago

Claude Code Essentials
How-To

Claude Code Essentials

FreeCodeCamp β€’ 3h ago

Discover More Articles