A Perplexing Javascript Parsing Puzzle

What does this print?

Think it through, then try it in a browser console! Answer and explanation in the dropdown.

Show answer

It prints 1.

wait wtf

At the beginning of a line (and only at the beginning of a line), --> starts a comment. The JavaScript is parsed as

The browser then displays the value of the last expression, which of course is 1.

but why

It’s a legacy hack.

Netscape Navigator 2 introduced both JavaScript and the

添加评论
点赞收藏
点踩分享查看原文
评论
?
参与讨论