Articles

How to get CSS values in JavaScript

CSS alone is not enough sometimes. You might need to control your CSS values with JavaScript. But how do you get CSS values in JavaScript?

Turns out, there are two possible ways, depending on whether you’re trying to get inline styles or computed styles.

Finding motivation

Many people rather relax than work.

They say they don’t feel motivated to work. They need to feel motivated.

Sounds familiar?

Looping through objects in JavaScript

Once in a while, you may need to loop through Objects in JavaScript. The only way to do so before ES6 is with a for...in loop.

The problem with a for...in loop is that it iterates through properties in the Prototype chain. When you loop through an object with the for...in loop, you need to check if the property belongs to the object. You can do this with hasOwnProperty.

for (var property in object) {
if (object.hasOwnProperty(property)) {
// Do things here
}
}

We no longer have to rely on for...in and hasOwnProperty now. There’s a better way.

Why you shouldn’t reassign values in JavaScript

In JavaScript, you can reassign values to variables you declared with let or var.

I used to reassign values a lot. But as I got better with JavaScript, I realized you shouldn’t reassign values if you can. This is because:

  1. You may change external state by accident when you reassign values
  2. You create more complex code when you reassign values

Dealing with overwhelm

It’s easy to feel overwhelm as developer. We have so many things to learn.

We need to learn HTML, CSS, JavaScript, accessibility, animations, frameworks, dev tooling, and new things that pop up every now and then.

I wouldn’t be surprised if you’re overwhelmed. I feel overwhelmed too. Every single day.

Why you learn when you teach

The best way to learn is to teach.

You’ve heard many people say this. But is it true?

I knew teaching had benefits. For example, if you teach, people will know you exist. People may be able to learn from your experience. But learn? I was skeptical.

But I realized the statement is true. You learn best when you teach. I can vouch for it after teaching frontend development for many years.

This article explains my thoughts on why teaching others help you learn.

Dealing with confusion

It’s normal to feel confused when you’re trying to learn something new.

Some people hate this feeling. I know I do. But it’s important to feel this confusion.

5 things I learned from Infinity Wars

Infinity Wars was amazing. I recommend you watch it—even if you think the plot, the cast, or even the ending sounds silly.

I learned five things from the movie. I want to share these things with you (and talk about how they relate back to life, coding, and learning).

Note: there’s going to be spoilers.

Hold on while i sign you up…

🤗
Woohoo! You’re in!
Now, hold on while I redirect you.