Post JSON data to an URL

The easiest way to do a POST in JavaScript: using fetch.

Infinite previous and next selection

Select each element in a selection loop. If you go forward as soon as you finish the list of elements you will start selecting from the beginning and the same if you go in opposite direction.

Don’t forget to use nextElementSibling and previousElementSibling (DOM Elements) instead of nextSibling and previousSibling (DOM Objects). A DOM Object can be anything: comments, insolated text, line breaks, etc. In our example nextSibling would have worked if we had set all our HTML Elements together without anything between then:

<ul><li></li><li></li></ul>

Get JSON data from an URL

AJAX request using ES6 Promises with fetch and XMLHttpRequest. Notice that the url needs https because we request from https and the server should allow all origins (Access-Control-Allow-Origin: *)

Fetch is simpler and cleaner, it avoid callback hell and having to remember the complex API of XMLHttpRequest.

Simon Game

Have you ever played to Simon? That game where you have to memorize an incremental sequence of colors. Today I’m bring to you this famous game in ES6 using CSS transformations and animations. Open it in a new browser window or tab and stretch or shrink the area to see how the game is always visible, there are not scroll bar at all, pure responsiveness, enjoy the play 🙂

Code once, run everywhere: Simon Game in Google Play

When should you use arrow functions in JavaScript?


Use it every time to can but I would recommend you to avoid ‘this’ as much as possible in your code because depending on the context it will represent different things.