The Task
Write a simple ES6 module, and run the code using Webpack.
In order to save you time, I uploaded each step of the tutorial on my GitHub account. Fork it from here.
Code Modularity
Code modularity is essential for writing maintainable code. ES6 modules offer solutions for encapsulation, packaging and information hiding. Implementing the module pattern enriches your application.
Module for financial account
We will create an ES6 module representing a financial account. We will store transactions belonging to the account in an array. Each transaction has the following attributes:
- amount : Integer in cents. Floating points are unreliable. Depositing 0.1 then 0.2 won’t give you 0.3 as a result.
- date : String in
"yyyy-MM-dd"
format. We will simplify things. If you feel like experimenting with the Date object or you just want to laugh a bit, read my post on Javascript dates!
We will import this ES6 module in another file, fill it with some data for demo purposes, and populate an ordered list with the three largest transactions.
Now, let’s start working on this task.
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.