1

For example, following code prints 1, which means that new line is treated as statement separator:

function f1() {
    return 1
    2
}

console.log(f1());

However, this example prints 3, which means that new line is ignored:

function f1() {
    return 1
    +2
}

console.log(f1());

How does Javascript decides when to ignore new line character, and when use it as a statement separator?

akalas
  • 11
  • 2
  • 1
    To oversimplify a bit, it assumes that a newline ends a statement if it would otherwise be a syntax error. `return 1 2` is a syntax error, whereas `return 1 +2` is not. –  Jun 24 '17 at 16:50

0 Answers0