7 things you didn’t know about JavaScript
Tags: JavaScript, Jquery, ES6

The WebAPI

JavaScript isn’t the same buggy language it was 10 years ago. One proof of this is the awesome WebAPI. It offers a rich variety of functionality, from DOM manipulation to notifications. Battery management to WebSockets. Camera functionality, SMS, telephony, Bluetooth and much more. The WebAPI got you covered. Go through the list yourself and find out things you never knew were possible in JavaScript!

jQuery is obsolete

In many cases

jQuery on Google trends, it’s time to move on

Many websites still load the whole jQuery library. Basic DOM manipulation, network communication or fancy animations, you think you need jQuery.

That was definitely the case 7 years ago, but not today. Now there is native JavaScript support for all these things. I already wrote about the WebAPI, well there’s a whole section about the DOM there. You’ll be astonished if you thought jQuery is the only way to easily manipulate the DOM. Animations can (and should) be done with CSS. ES2015 introduces the Promises/A+ API, which makes network communication (and a lot more) super convenient. One more thing: native JavaScript is way more performant. But please don’t take my word for it, take a look at this comparison before judging.

Object oriented

Many people tried to hack classes in JavaScrip. They made complex frameworks to mimic class-like behaviour. However, JavaScript was never meant to be class oriented. Although that might sound bad, it doesn’t mean it’s not object oriented. Kyle Simpson points this out in his You don’t know JS series about “this and object prototypes”:

In fact, JavaScript is almost unique among languages as perhaps the only language with the right to use the label “object oriented”, because it’s one of a very short list of languages where an object can be created directly, without a class at all.

JavaScript for sure isn’t class oriented, it’s prototype oriented. Even with the ES2015 class syntax, we’re still dealing with objects and prototypes under the hood. Kyle introduced a prototype oriented pattern called OLOO, which you might want to check out. Furthermore, you can read about the basics here.

WASM

WASM, or WebAssembly adds a new language to the browser for super performant code. It will also be a compile target for other languages like C and C++ (we mostly use asm.js today). It’s a very complicated topic, so you should read most about it somewhere else. Long story short: other languages can be compiled to work in the browser. JavaScript will also be able to communicate with this layer.

Object.observe()

Edit: Object.observe has been removed from the ES2016 spec. You can read more about it here: https://esdiscuss.org/topic/an-update-on-object-observe

This might seem like a small thing, but it actually has a lot of implications. ES2016 specifies an implementation to observe objects, allowing for performant two-way data binding. Although ES2016 (you might know it by ES7) is not yet finalised, there are a lot of platforms already implementing this feature. It’s definitely worth taking a look at. It will influence a lot of modern frameworks which exist today.

Jafar Husain of Netflix talked about the Observable pattern and async JavaScript at HTML5DevConf, a related topic you can check out if you haven’t yet. (This talk is still very accurate today, although Object.observe isn’t in the spec anymore).

Web components

You’ve probably heard about web components and the shadow DOM before, so let’s just say HTML and JavaScript will become much more modular and reusable. This talk by Jarrod Overson might already be a bit dated, but it opens your eyes if you have no idea what the impact of web components is and will be. It won’t take long and even jQuery plugins will be obsolete. We’ll just download a web component which will work perfectly with native JavaScript. Just to name one example.

Legacy code

I’ve summed up some very cool features. Some of which are fully supported today, some are being implemented right now. Some are only early draft. This raises the issue of different browsers and browser versions which need support. That has been a problem for as long as the web has exist. Transpilers and polyfills can do a lot but not everything, and performance is a thing to keep in mind too. I believe the way we develop applications for the web today will drastically change in the next few years.

I’ve written about this topic in another post. When you have 5 minutes to spare, you could read about JavaScript for desktop applications over there.