2

Are the escape and unescape functions of underscore and lodash the same? So can I escape with lodash and unescape with underscore and always get the same string?

I may want to switch from vanilla https://stackoverflow.com/a/12034334/1707015 to https://stackoverflow.com/a/18756038/1707015 and have to connect different components.

qräbnö
  • 2,722
  • 27
  • 40

1 Answers1

3

Apart from the fact that Underscore escapes backticks and Lodash doesn't, they serve the same purpose and are interchangeable.

The second answer you're linking to contains a remark that Lodash offers the same API as Underscore, but is written to be more performant. I should point out that this remark is no longer true, if it has ever been.

Right from the start, Lodash has diverged significantly from Underscore, introducing more breaking changes with every major release. Although many functions are still roughly the same (such as escape) the libraries are not interchangeable in general nowadays.

The performance advantage should also be taken with a grain of salt. While Lodash does prioritize performance more than Underscore, most applications will not notice the difference, and there is also some anecdotal evidence of applications actually being a little bit faster with Underscore. Lodash is also four times larger than Underscore. So for a performance-based decision, you should benchmark your application with both libraries (which is not easy in general, given that they are not entirely interchangeable) and then weigh the speed difference against the size difference.

So choose wisely!

Full disclosure: I'm the maintainer of Underscore.

Julian
  • 4,176
  • 19
  • 40
  • 1
    Thank you very much. So the answer is No. Bloody backticks :D I will therefore always make comparisons either unescaped or escaped, i.e. I will not mix lodash and underscore. – qräbnö Jan 22 '21 at 17:59