Line continuation characters in JavaScript

前端 未结 4 456
情话喂你
情话喂你 2021-02-03 17:21

What is the best practice for line continuation in JavaScript? I know that you can use \\ for strings. But how would you split the following code?

4条回答
  •  逝去的感伤
    2021-02-03 17:31

    The "+" is for concatenation of strings and most of the examples are dealing with strings. What if you have a command you need to string across multiple lines, such as a compound "if" statement? You need a backslash at the end of each line that is to be continued. This escapes the invisible next line character so that it will not delimit the command in mid statement.

提交回复
热议问题