Line continuation characters in JavaScript

前端 未结 4 449
情话喂你
情话喂你 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:47

    If I properly understood your question:

    var statement = con.createStatement('select * from t where '
                                      + '(t.a1 = 0 and t.a2 >=-1) '
                                      + 'order by a3 desc limit 1');
    

    For readability, it is fine to align + operator on each row: Anyway, unless you're using Ecmascript 2015, avoid to split a multiline string with \, because:

    1. It's not standard JavaScript
    2. A whitespace after that character could generate a parsing error

提交回复
热议问题