Home  >  Q&A  >  body text

Problems with nested single quotes and double quotes

First sentence: var str = "My name is'" name "'"

Second sentence: var str = "My name is\"" name "\""

You said that only double quotes can be nested within single quotes, and only single quotes can be nested within double quotes. I can understand the first sentence, but I can't understand the second sentence because it is full of double quotes.

自律者自由自律者自由2551 days ago2227

reply all(3)I'll reply

  • nearest

    nearest2017-10-26 00:11:24

    \ is an escape character, and the symbols following it become entity output, and there are no quotation marks here.

    reply
    1
  • 豆豆

    豆豆2017-10-25 23:43:41

    "My name is\"", in fact, I want to output: My name is"

    and then connect the name,

    "\"", this output is",

    The final output is: My name is "name",

    \ is the escape character, if there is no \ in "\"", the syntax is wrong, and with \, has become escaped, you can output the "


    immediately following \

    reply
    1
  • 路过

    路过2017-10-25 08:46:35

    \ This is called an escape character, which means that the symbol behind it is directly output

    reply
    1
  • Cancelreply