Why I Hate Lodash

This article explains why I hate Lodash, including usage scenarios and implementation details, to improve understanding of the issues with over-relying on Lodash.

Feb 16, 2020 · 2 min read · 338 Words · -Views -Comments · Programming
JavaScript 🇨🇳 阅读中文版
Read with AI

Choose an AI assistant

ChatGPT Open in a new tab with the article link and prompt
Claude Copy the prompt, then open Claude

Open Claude
Trouble reading the article?

If the prompt is missing, copy the full prompt below into your AI assistant. If the AI cannot read the article, paste the visible passage you want to discuss and add your question.

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?
Authors
Developer, digital product enthusiast, tinkerer, sharer, open source lover