How to add single quote in the variable in Javascript?

前端 未结 4 1085
深忆病人
深忆病人 2020-12-11 01:33

I have variable var str as following:

var str = ;

I would like to make it as below

4条回答
  •  攒了一身酷
    2020-12-11 02:30

    We can use the backslash () escape character to prevent JavaScript from interpreting a quote as the end of the string.

    The syntax of \' will always be a single quote, and the syntax of \" will always be a double quote, without any fear of breaking the string.

    Using this method, we can use apostrophes in strings built with ".

    'We\'re safely using an apostrophe in single quotes.' We can also use quotation marks in strings built with ".

    "Then he said, \"Hello, World!\"";

提交回复
热议问题