Portfolios that get you hired. Find out more...

3 Reasons Why It's Hard to Grasp JavaScript `this`

If you are struggling with JavaScript `this`, it's NOT YOUR FAULT! The truth is, it can be a tricky subject. It trips up a lot of people, not just you.

If you're learning JavaScript as your first language, fear not. I've tried to assume as little as possible. You can also get in touch if there is something you believe should be changed or explained in more detail.

If you're coming from another language, you should know that JavaScript `this` has its own way of acting. It is simply not the same as what you're used to. Don't worry, soon you'll have a full grasp of how `this` works.

It's crucial that you have the right mind frame when learning JavaScript `this`. For this reason, I decided to start with the reasons why you might struggle with `this`. Here we go...

#1 - You must first grasp a couple of other JavaScript concepts

You have to know certain JavaScript concepts before you can grasp `this`. Especially when it gets weird - 'coz it does get weird. That's why you'll first learn the basics of JavaScript objects.

As you progress, you'll discover a lot of cool stuff that will help you have a deep grasp of `this`. You will then become a better, more confident developer. You will have skills that will serve you way beyond using `this`.

#2 - You can't know what `this` is just by looking at the code where it's created

This is a big one. When you come across `this` in code, you can only figure out part of what `this` is supposed to be. Why? Because where `this` is created has almost no bearing on what it represents when the code is run. So, don't beat yourself up!

#3 - You are too hard on yourself

Look, being a self-taught developer is no easy task. You should pat yourself on the back for having the courage to even attempt such a feat. With nothing but your sheer guts, you're learning one of the most valuable skills of the modern age. Think about it - if it were easy, everyone would be doing it.

Some JavaScript concepts are tricky. After all, the language was created in just a week! Yet, we have to leave with all the design decisions, good and bad. The point is, be patient with yourself.

It's like riding a bicycle - you'll fall and get bruised a few times. But, once you've got it, you have it for the rest of your life. You will be a proud master of a skill that will have a direct impact on your career.

So, take your time. Take a break after each section. Reward yourself for each bit of progress you make, no matter how tiny it may seem. With that in mind, let's start grasping `this` by looking at JavaScript objects...

Next: your first step to understanding JavaScript `this`...

Self-taught developers: tips for writing code that gets you hired! Join now!