javaScript example tax brackets
So for todays javaScript examples post I thought I would throw together a quick module that can be use to get the basic idea of a progressive tax system up and running. This is one thing that comes to mind when creating a collection of javaScript examples, and it is also something that I would like to have a basic general understanding of anyway.
the aim here is to not make something that would be used to seriously work out ones taxes. The aim is to work out a simple bracket system that might coincide with a real life system or not. In any case do not use what I work out here to do your taxes, but if you want to find a starting point when it comes to gaining an understanding as to how a progressive tax system works maybe this is a good starting point, but I would look for additional resources of course.
1 - The tax module for the javaScript example
First off I want to work out a javaScript module that I can use to create a tax object of sorts. This tax object will have an array of bracket objects, and some top level properties for total tax and tax percent. In the module there will be helper methods to make the various objects for the main tax object, a bracket object and so forth.
I will want to put in some hard coded tax bracket data that will act as a default, however will also accept it as an argument. I will then also have a method to figure tax for each bracket, and a main public method that can be used to return a tax object with a given amount of income. For this set of hard coded data I was able to find a decent post on United States income tax for 2019, This would just need to be updated now and then, or pulled into a more appropriate form such as a JSON file.
|
|
So for the hard coded data I went with the 2019 tax table data.
2 - Now for a demo the makes use of the module
So now that I have my tax module worked out it is time to use it in in a HTML file. I want to just have a simple project that just has an input text element that I can use to input a taxable amount of money, and then a total tax is displayed as well as a breakdown for each tax bracket.
So then I have a single update method that is called once, and then each time a key up event happens with the input element that is used to enter an amount of money that is subject to tax after deductions. This update method uses the public metjod of the tax module to get the main tax object that is used in rendering.
|
|
3 - Conclusion
This was just an idea that I had for expanding a collection of posts on javaScript examples. I do not recommend using this as a way to figure out your taxes for real, it was just an idea to gain better sense of how a system like this works. I might get around to expanding this further if i get some time to do so, but I have many other posts and projects begging for my attention so I would not count on it. However that might change if enough people express interest in this post and the javaScript code, if so let me know of anything that comes to mind in the comments.