Idle JavaScript Observations

Friday, June 4th 2021

There are lots of blogs that post useful tips and observations about programming in JavaScript and other languages.

This is not one of them.

Sometimes I like to look at the label documentation for JavaScript on MDN and ponder unusual ways I can use it:

The way Svelte makes use of the label syntax is actually kind of interesting. When I did a deep-dive into that framework last year this jumped out.

But a deep-dive into labels and scoping might actually be useful. This post is just to let you know that this is valid JavaScript:

In fact, copying-and-pasting just about any URL is probably valid JavaScript.

Why is this?

  • The http(s) protcol gets interpreted as the aforementioned label.
  • The // immediately following the label starts a comment.

The lowdown: you can copy and paste just about any website directly into your JavaScript code without modification and it won't break anything.

Is this useful? Not really. Just a funny observation I learned the hard way, when I forgot to copy out the reference to some documentation elsewhere in my code.

Filed under: Useless JavaScript.