JavaScript’s typeof operator should be ignored. It’s broken.

JavaScript’s typeof operator should be ignored. It’s broken.

A more reliable test for data types:

Object.prototype.toString.call(data);

For example:

Object.prototype.toString.call([]); // [object Array]

Object.prototype.toString.call({}); // [object Object]

Object.prototype.toString.call(”); // [object String]

Object.prototype.toString.call(new Date()); // [object Date]

Object.prototype.toString.call(1); // [object Number]

Object.prototype.toString.call(function () {}); // [object Function]

Object.prototype.toString.call(/test/i); // [object RegExp]

Object.prototype.toString.call(true); // [object Boolean]

Object.prototype.toString.call(null); // [object Null]

Object.prototype.toString.call(); // [object Undefined]

Paste this into your browser’s console:

Paste this into your browser’s console:

setInterval(_=>{

document.body.innerHTML = “

” + [

…”๐Ÿ˜ฎ๐Ÿ˜€๐Ÿ˜๐Ÿ˜๐Ÿ˜‘๐Ÿ˜ฌ”

][new Date%6]

}, 99)

https://mobile.twitter.com/aemkei/status/941410298388537346

Currently reading Functional Light JS by Kyle Simpson.

Currently reading Functional Light JS by Kyle Simpson. You can read this for free online https://github.com/getify/Functional-Light-JS or buy the ebook from Leanpub.

This book explores the core principles of functional programming (FP) as they are applied to JavaScript. But what makes this book different is that we approach these principles without drowning in all the heavy terminology. We look at a subset of FP foundational concepts that I call “Functional-Light Programming” (FLP) and apply it to JavaScript.

Axel Rauschmayer is running an excellent series of blog posts introducing and exploring in some depth features of…

Axel Rauschmayer is running an excellent series of blog posts introducing and exploring in some depth features of the ReasonML programming language. http://2ality.com/archive.html?tag=reasonml

Reason is a new language created by Facebook which uses a C-like syntax similar to JavaScript but is implemented in OCaml under the hood. OCaml is a robust and mature functional programming language which is over twenty years old.

Reason compiles to JavaScript, web assembly and native.

The latest installment of this series is a pretty deep dive into how functions are defined in Reason. http://2ality.com/2017/12/functions-reasonml.html

Rauschmayer is well known in the developer community for writing in-depth books explaining the various syntax nuances of JavaScript. You can read his books for free at his website.