Due to a bug in the original C code for the implementation of Javascript, this awesome thing happens:

const a = null;
console.log(typeof a); // prints "object"
Read more

Here's yet another one of Javascript's endless oddities: the switch statement uses strict comparison (think === instead of ==).

Read more

There's a bunch of Web APIs that are pretty usable today:

  1. Detect page visibility
  2. Detect online state
  3. Vibration
  4. Detect orientation

...and more! clipboard, ambient light detection, battery status, etc.

Read more

You can run timers on the console object, like this:

console.time('a');
costlyOperation();
console.timeEnd('a'); // outputs how much time has passed since the call above
Read more

There's a nice utility that you can use to kill a process based on the port it's listening to, so for example if you have a server listening on port 80, you can run $ fkill :80 and it will murder it.

Only problem, it's made using Javascript, but if you're OK with having Node and plain-text JS files in your bin folder, you can install it with $ npm install --global fkill-cli.

Read more

Javascript's Date object has a bunch of methods to format dates as strings, including toLocaleDateString(). This method has options for controlling the format, which include language but also more granular options such as "use 2-digit years" or "show long weekday names".

Here are some examples (tests were done in Chrome 64):

Read more

In order to use a variable as an object's key, ES6 introduced something called "computed property names", where you add brackets to your variable and it gets replaced with its value.

Read more

JSON.parse() has an optional second parameter meant for a "reviver" function. This function will receive all keys and values from the parsed string, so you can do modifications to the result. This is useful, for example, to convert date strings to objects automatically.

Read more
Subscribe to JavaScript
Mastodon Mastodon