DEV Community

Cover image for Using Backticks as Syntactic Sugar in JavaScript and Scheme
Justin Ethier
Justin Ethier

Posted on

Using Backticks as Syntactic Sugar in JavaScript and Scheme

ECMAScript 6 introduced the concept of template literals to provide a convenient way to build up strings in JavaScript.

For example:

> let h = "Hello", w = "World";
> `${h} ${w}!
  ${h} ${w} from line 2`

"Hello World!
Hello World from line 2"
Enter fullscreen mode Exit fullscreen mode

This is reminiscent of using backticks in Scheme to construct lists using quasiquotation:

> (let ((h 'hello)
      (w 'world))
  `(,h ,w !))

(hello world !)
Enter fullscreen mode Exit fullscreen mode

Maybe its not a coincidence that template literals were called quasi-literals when originally proposed:

This scheme extends EcmaScript syntax with syntactic sugar to allow libraries to provide DSLs that easily produce, query, and manipulate content from other languages that are immune or resistant to injection attacks such as XSS, SQL Injection, etc.

Especially since there are no other commonly-used languages that use backticks for string interpolation.

Anyway, thought this was an interesting observation on the evolution of the JavaScript language.

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

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

πŸ‘‹ Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay