Why I Hate Lodash

· 2 min read

During project development and code reviews, I consistently recommend that teams reduce their dependence on Lodash and use native JavaScript instead. Whenever I see someone using it, I pay attention and repeatedly ask why they need Lodash. Here I’ll explain why I dislike it so much.

  1. Lodash provides many utility functions, both those you know and those you don’t. Overuse leads to over-dependence, and you may end up knowing Lodash but not native JS, preventing proper learning of native JavaScript due to heavy Lodash usage
  2. Depending on Lodash realistically means increased bundle size, though with today’s high bandwidth and fast internet speeds, this size increase might not be a major concern
  3. When both native methods and Lodash can accomplish the same functionality, using Lodash may mean worse performance.
  4. Lodash methods consider many edge cases comprehensively, so they have stronger error tolerance, but you should know that not throwing errors is sometimes more dangerous than throwing them. For example, with find and get methods - no error doesn’t necessarily mean correctness.
  5. Some Lodash methods like the get method actually cause type information loss, and path access parameters lose static analysis capabilities, making things like refactoring harder to detect.
  6. Some Lodash methods can cause errors if you’re not familiar with them. For example, with isEmpty, you should know that _.isEmpty(true) returns true

Attitude Towards Using Lodash

  1. For specific functionality, prioritize native JavaScript approaches, considering target browser compatibility
  2. When importing Lodash, use ES module tree-shaking imports to reduce bundle size to some extent
  3. I recommend this repository - You-Dont-Need-Lodash-Underscore. Through this repository, you can understand how experts view Lodash and learn how to implement equivalent functionality natively
  4. I’m not saying don’t use it, but I resent and reject mindlessly using Lodash to solve problems without thinking, because I believe these people don’t consider whether native solutions exist or think about performance - to put it emotionally, they have no sense of guilt.
  5. For those blind Lodash fans, what will you do someday when there’s no Lodash dependency in your development environment?