News for hackers. Stuff that matters.
Re:Most URLs are syntactically valid JavaScript code by honie on Friday July 23, 2021 @06:22AM (#27929093)
> The lowdown: you can copy and paste just about any website directly into your JavaScript code without modification and it won't break anything.

The following doesn't seem to be valid though. :( Am I missing something?

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/label

    let a = 1;
Re:Most URLs are syntactically valid JavaScript code by lhorie on Friday July 23, 2021 @11:10AM (#27931544)
Sort of the same reason why `if (true) let a = 1` is a syntax error (and the error message says why: "Lexical declaration cannot appear in a single-statement context")

The rationale here is that the variable goes out of scope right away due to the implicit block, so they made it a syntax error so that you don't waste time pulling your hair out debugging issues downstream from this line without realizing this scope-related obscurity. (This also has potential security implications e.g. if you think you're shadowing a variable from a parent scope but you're not)

Re:Most URLs are syntactically valid JavaScript code by maxbond on Friday July 23, 2021 @06:59AM (#27929337)
```

>> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

10

<- 10

```

Eg, this is equivalent to:

```

>> https: 10

```

Re:Most URLs are syntactically valid JavaScript code by honie on Friday July 23, 2021 @07:05AM (#27929374)
Yes, but that's not related to code example I gave, which produces a syntax error.
Re:Most URLs are syntactically valid JavaScript code by maxbond on Friday July 23, 2021 @05:41PM (#27935941)
My bad, I misunderstood.