문제

What are the parsing rules regarding the debugger keyword?

On Chrome, the following works fine:

debugger
console.log('Hello!')

but

debugger console.log('Hello!')

is a SyntaxError.

Why is replacing one form of whitespace (new line) by another form of whitespace (space) so critical? What are the parsing rules for debugger?

도움이 되었습니까?

해결책

This is not related to the debugger statement at all, it's down to automatic semi-colon insertion.

It's the same as trying

alert('Hi');
console.log('Hello');

and

alert('Hi') console.log('Hello');

Automatic semi-colon insertion is turning your input into;

debugger;
console.log('Hello!');
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top