4

Idle JavaScript Observations

 3 years ago
source link: https://george.mand.is/2021/06/idle-javascript-observations/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Idle JavaScript Observations

Sunday, June 6th 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:

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

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:

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

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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK