Balance as Private Field
Part of the Object Oriented Programming section of Coddy's JavaScript journey — lesson 23 of 56.
Challenge
Let's make the BankAccount class more secure by converting the balance to a private field."
Your task:
- Add
#balanceat the top of the class - Change
this.balancetothis.#balancein the constructor - Change
this.balancetothis.#balancein all methods
Try it yourself
import { BankAccount } from './bankAccount.js';
// Test the implementation
const testAccount = new BankAccount('Alex Johnson', 500);
console.log(testAccount.getAccountInfo()); // "Alex Johnson: $500"
console.log('Balance:', testAccount.getBalance()); // still works: 500
console.log('Balance:', testAccount.balance); // undefined
All lessons in Object Oriented Programming
1Objects & The this Keyword
Quick Review: ObjectsAdding Methods to ObjectsUnderstanding the this KeywordConstructor FunctionsThe new KeywordRecap Challenge7 Inheritance & The extends Key
InheritanceThe "is-a" RelationshipThe extends KeywordThe super() MethodInheriting Properties&MethodsRecap Challenge2Organizing Code
What are Modules?Exporting with exportImporting with importDefault vs. Named Exports8Organizing OOP Code
Organize Classes into Modules11Project: A Shape Renderer
Setup: Shape Class & ExportCircle Class Inheritance9Static Methods & Properties
Class-Level vs. Instance-LevelStatic PropertiesStatic Utility MethodsRecap challenge