if (true) {
let x = 5
}
works as expected (no syntax error), but
if (true) let x = 5
throws SyntaxError: Unexpected strict mode reserved word
in Node 4.1.0 and babel
Is this expected behavior? I know that this is a stupid example. I'm just wondering wether this is a bug or not.
Yes it is expected behavior. The production rule of an
if
statement isbut a
let
declaration is not aStatement
and is therefore not allowed in this position: