DEV Community

George Jempty
George Jempty

Posted on • Edited on

2

The Pro's and Pro's of Javascript String Templates

Yep, you read it right, the Pro's and Pro's (not Con's). This morning I committed code containing a string template as follows:

alert(`You've found the solution (${solution}) !!`);

Actually I started with double-quoted segments and concatenation, so the apostrophe in "You've" didn't cause an issue. But had I started with single quotes, I'd have had to escape that apostrophe.

I knew I shouldn't be doing the string concatenation and so changed to the string template as above. But it dawned on me, that by using a string literal, you don't have to escape either single or double quotes inside the string.

That's just one Pro. I decided to write a JSPerf to be sure there weren't any performance ramifications. But on Chrome anyway, the differences are infinitesimal. YMMV (your mileage may vary) but until then I'm sticking to my guns: Pro's and Pro's ;)

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more