Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comment in multiline string in JavaScript

Is there a possibility to add comment inside a javascript multiline string?

Something like this:

var string = 'START - \
This is part of my string\
\\ This should be escaped!\
-END ';

// string = 'START - This is part of my string - END';

Thanks

like image 976
Charles Avatar asked Apr 20 '26 11:04

Charles


2 Answers

I found one possibility:

var string ='START - \
This is my string'+
// This should be escaped!
' - END';

// string = 'START - This is my string - END'

But it's not so nice...

like image 115
Charles Avatar answered Apr 22 '26 01:04

Charles


It's not possible this way. You can do:

var s = "multi line" +
        //" line" +
        " string";
like image 28
marekful Avatar answered Apr 22 '26 00:04

marekful



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!