When to use the {js| |js} quoted string?


It appears that usage of {js| |js} and {j| |j} are similar, but with the latter supporting variable interpolation.

Could we always just use {j| |j} or are there some cases when it would be better to use {js| |js}?



The only obvious case I can think of is when you don’t want to escape the dollar signs, plus it shows right away there’s no string interpolation in this string, which can improve code readability.

But maybe there are other reasons too.


I could imagine js is faster to parse and should be preferred when you have really big strings where you need unicode support, but that can possibly only be answered by @bobzhang or any other person with deeper insights into the compiler.


I thought of that too, but it seems it’s actually parsed at build time, so there’s probably no difference at runtime.

let foo = {js|foo|js};
let bar = {j|bar|j};
let baz = {j|Hello $foo|j};


var foo = "foo";
var baz = "Hello " + (String(foo) + "");
var bar = "bar";


Yeah, sorry. I was referring to build time. So it’s probably negligible for most people.


@tsnobip @fham thanks :pray:


Use j at most time, only use js when your quoted string has {j| as well which would cause a lexing issue but it’s rare in practice