unterminated string literal

前端 未结 9 1342
轮回少年
轮回少年 2020-11-30 06:07

The following code:

var str= \"English Comprehension<\\/strong>
                    
                    
9条回答
  •  野性不改
    2020-11-30 06:30

    It is not a best practice to write multiline strings in Javascript.

    But, you can do that with the \ terminator:

    var str= "English Comprehension<\/strong>\
                    \
                    
      \
    • Synonyms/Antonyms/Word Meaning (Vocabulary)<\/li>\
    • Complete the Sentence (Grammar)<\/li>\
    • Spot error/Correct sentence (Grammar/sentence construction)<\/li>\
    • Sentence Ordering (Comprehension skills)<\/li>\
    • Questions based on passage (Comprehension skills)<\/li>\ <\/ul>\ ";

    Note that trailing spaces are part of the string, so it is better to get rid of them, unless they are intentional:

    var str= "English Comprehension<\/strong>\
    \
    
      \
    • Synonyms/Antonyms/Word Meaning (Vocabulary)<\/li>\
    • Complete the Sentence (Grammar)<\/li>\
    • Spot error/Correct sentence (Grammar/sentence construction)<\/li>\
    • Sentence Ordering (Comprehension skills)<\/li>\
    • Questions based on passage (Comprehension skills)<\/li>\ <\/ul>\ ";

提交回复
热议问题