How come that this string
"answer to life the universe and everything is #{40+2} "
compiles into
" answer to life the universe and everything is " + (40 + 2) + "";
how can I force coffescript to keep it multiline (keeping string interpolation intact):
"answer \ to life \ the universe \ and everything \ is \ "+(40+2)
There are three ways to create a multiline string in JavaScript. We can use the concatenation operator, a new line character (\n), and template literals. Template literals were introduced in ES6. They also let you add the contents of a variable into a string.
Use triple quotes to create a multiline string It is the simplest method to let a long string split into different lines. You will need to enclose it with a pair of Triple quotes, one at the start and second in the end. Anything inside the enclosing Triple quotes will become part of one multiline string.
Try using the heredoc
syntax:
myString = """ answer to life the universe and everything is #{40+2} """
This converts to this javascript:
var myString; myString = "answer\nto life\nthe universe\nand everything\nis\n" + (40 + 2);
There's not really any point to make it actually be on newlines in the compiled javascript visually, is there?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With