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"
This is reminiscent of using backticks in Scheme to construct lists using quasiquotation:
> (let ((h 'hello)
(w 'world))
`(,h ,w !))
(hello world !)
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.
Top comments (0)