Simple and obvious answer - for the code to run faster (duh!). But does it really matter? It depends. Let's say your code runs in a cloud. In that case an optimized piece of code can save you hunderds, thousands and even hundreds of thousands of dollars depending on the scale it is running at. Keep in mind that there are certain features of each and every language that are baked in and it makes sense to think your use case through thoroughly before implementing it. Having said that, for a client side code even a small optimization could go a long way, especially when we're talking about something on the UI side - that would obviously improve usability.