A 3-post collection

Adding Negative Indexes to JavaScript Arrays

Every time I return from ruby/python to JavaScript I'll fall into the same mistake of writing arr[-1] and not getting the last item. JavaScript has a weird way of stringifying object keys which leads to stringifying array indexes which renders the above nonsense there. Luckily JavaScript is also great at monkey patching, so let's see if we can fix negative indexes there. Take 1: -1 Is A Valid Index Since JavaScript stringifies keys -1 is just as valid array index as foo, bar, 2

Read more

3 Cool Uses For Tagged Template Literals

ES6 Template literals have become one of my most used JavaScript features. Tagged template literals work about the same way but let you write your own "tagger" or handler function which does the interpolation. Why would you want to? I could think of 3 reasons. But first the gory details

Read more