Answer: Is this a valid use case for javascript closure?

twitter logo github logo ・1 min read

I was trying to come up with a practical example of information-hiding/encapsulation and this is what my attempt so far

'use strict';

const bank = (accountHolderName, initialDeposit) => {
    let balance = initialDeposit;
    const add = (amount) => {
        balance += amount;
    }

    let subtract = (amount) => {
        balance
twitter logo DISCUSS
Classic DEV Post from Mar 27 '18

Changelog: Suggested follows on onboarding!

Harit Himanshu profile image
I am hands-on software professional with more than a decade of experience in building and shipping products at companies of small to large sizes. contributed in Advertising,CleanTech,Security,FinTech