ken

Hi, I’m Ken Mazaika and I’m the CTO & Co-founder of The Firehose Project.

When you set out to learn JavaScript, you might start asking yourself a lot of questions.  Questions like:

  • Why is this so hard?  
  • Am I the only one to think this is confusing?  
  • Will I ever actually enjoy writing programs in JavaScript?

Most programming languages are like the board game Othello. They take a minute to learn and a lifetime to master. JavaScript is far more complex. It reminds me of the board game Diplomacy, which might be the most frustrating game ever invented.

In this article, we’ll get into the 7 key reasons why JavaScript is so difficult to learn. We’ll also touch on why it’s worth learning and how it’s such a useful programming language for modern programmers.

Let’s jump into it.

1. JavaScript is so hard to learn because in order to do interesting things in JavaScript, you need to use the advanced features of JavaScript.

As you set out to learn JavaScript, you’ll quickly realize that you need to figure out a number of JavaScript-related technologies in order to build useful applications. These are additional topics that aren’t traditional JavaScript but are things you need in order to actually write JavaScript.

Performing HTTP requests (AJAX) Requests Through a RESTful JSON API.

You need to be able to do this in order to make writing JavaScript inside a web browser useful. So most JavaScript code you write will leverage this functionality.

Similar functionality can be done in other programming languages: like ruby, python, or Java. But this is advanced functionality that you can do later down the line. In Javascript, you need to understand this advanced functionality in order to do anything interesting at all.

Let’s talk about what this actually means:

HTTP Requests are what happens when you visit a website or click on a link. The HTTP request is a request from your computer to an external resource located somewhere on the Internet. HTTP requests are generally split into two main parts:

  • URL
  • HTTP Verb

The URL is the input that you type into the top part of your browser window (e.g. like “google.com”). The HTTP Verb allows you to view a page (a GET request) or indicate  that you want to create something new (usually via a form submission), delete an item, or make a change with different HTTP verbs.

Most of the time, HTTP requests result in the output of web pages (like this web page you’re reading this on). However, they don’t necessarily need to come back with web pages. Instead, they can come back with what’s known as JSON (or a “JavaScript representation of something.”)

This probably sounds complicated, so let’s get into an example.

Say you were building a website about cat facts. The page could display a cat fact on the screen. For example, something like: “All cats can speak English.” I’m 99% sure this is not true.

However, instead of showing you a web page that displays your cat fact, your request could also come back with a JSON- a machine-readable representation of the fact.  Here’s what it could look like:

Screen Shot 2016-08-29 at 6.18.51 PM

The above code is an example of JSON.

There are three things that almost all JavaScript code that is written inside a web browser will need to do:

  • Perform an HTTP request to a different web address
  • Parse the result of the HTTP request to get relevant information
  • Do something with the result of the HTTP response

In other programming languages, stuff like this is considered advanced. Most beginners wouldn’t even try to tackle until they’ve spent months working with that programming language. However, with JavaScript, you need to do leverage these advanced features right away in order to actually take advantage of its power.

2. JavaScript is so hard to learn because it’s powered by an event queue.

The event queue is invisible to developers. But without it working, your JavaScript code won’t do anything.

The event queue allows you to say:

“When [SOMETHING HAPPENS] I want you to do the following [CODE TO EXECUTE HERE].”

JavaScript has a nature of waiting until something happens, then “magically” triggering the right code at the right time. This can be pretty daunting for beginners. How can you know that the code will be executed at the right time?  As a developer, you need to trust that the event queue will fire things when (or close to when) it should. It’s difficult to become comfortable with that.

A lack of clear vision into something so core to the language can make you feel like you’re missing something. You find yourself questioning what will happen, and you tend to think:

“I know I told JavaScript to execute this when this event happens, but how does JavaScript know I should execute this then?”

So, what’s the answer? Well, you need to learn to trust that the event queue will do the right thing. The problem is that blindly trusting something you don’t fully understand can be really difficult. It’s especially difficult when you’re first starting out.

3. Javascript is so hard to learn because in order to get things done in JavaScript, you often need to understand complex Computer Science topics.

In programming, “defining a function” groups a section of code and gives it a name. There is also the concept of anonymous functions, which are “nameless functions”, meaning they leverage different aspects of functions outside of the ability to name a section of code. There’s also a computer science concept of a thunk, which is often used in functional programming languages that are generally taught at universities (languages like lisp, scheme, racket, oCaml, etc.).

These concepts come into play early on with JavaScript.

Javascript tends to feel more complex than other languages because it forces you to tightly integrate these complex computer science topics with the ability to just get things done. Languages like ruby usually support these features. But they aren’t introduced to complete beginners without much of a background in programming.

It’s difficult to learn these types of advanced coding concepts early in your programming experience. So it makes JavaScript so hard to learn.

Try to remember that these concepts will become tremendously useful as you continue to learn and grow as a developer.

4. JavaScript is so hard to learn because it’s an asynchronous programming language

It’s also single-threaded, which means it uses its asynchronous nature in a radically different way than most other programming languages.

What do I mean by asynchronous? Well, asynchronous means that work is happening, but it’s not happening right at the same time as something else. Take this example:

Say I wanted to call you (yes, I still call people…texting doesn’t work for everything) to schedule some time to play Pokemon Go together. There are two ways the conversation could go. We could communicate synchronously. Or we could communicate asynchronously.

Synchronous Version

Ken: “Hey are you available to play Pokemon tomorrow at 6PM?”

You:  “Hold on, let me check my calendar….. Yeah, that works. Let’s meet then.”

Asynchronous Version

Ken: “Hey are you available to play Pokemon tomorrow at 6PM?”

You: “I don’t know let me check my calendar and get back to you later.”

You (15 minutes later via email):  “Following up about playing Pokemon. Let’s do it tomorrow at 6PM.  Excited to gain some more experience.”

Most things in JavaScript happen asynchronously, which can feel backward compared to most other programming languages. Generally, in JavaScript, you will never wait for something that takes a long time to complete. Instead, you’ll put it into motion, start doing other work, and be reminded when the “first something” is finished.  

In most programming languages, you break your program up into concrete steps:

  • First, do this and wait for it to be finished before moving on to the next thing.
  • Then, do that and wait for it to be finished before moving on to the next, next thing.
  • etc.

But in JavaScript, you use a different type of workflow that eliminates any waiting. It goes like this:

  • First, do this and move on to the next thing, but notify me when it finishes.
  • Then, do something else and notify me when it finishes.
  • [then later]
  • Finally, notify me that the first thing is finished.
  • Finally, notify me that the second thing finished. (but not necessarily in this order).

It can feel weird to break tasks apart into concrete steps that don’t wait to finish before moving onto the next thing. But over time, after you write more and more JavaScript code, it becomes more natural.

The syntax can feel messy if you’re trying to do things in a synchronous way, which is how almost all other programming languages guide you to breaking apart problems.

Once you get familiar with the syntax of JavaScript and you get good at thinking about things in that way, JavaScript will feel much more natural. Eventually, it can feel like an elegant solution to a common problem that you’ll probably run into: building an asynchronous-driven programming language.

5. Javascript is so hard to learn because jQuery can be both a blessing and a curse.

In addition to the JavaScript programming language itself, most people want to interact with the web page in a meaningful way. In order to do this, developers need to interact with web APIs that the browser provides for you to interact with the webpage itself. Initially, web browsers had many problems, such as:

  • Browsers were inconsistent in the way that they worked with web pages.
    • If something worked with Firefox, it wouldn’t work in Internet Explorer (or vice-versa.)
  • Often, many lines of code were required to do simple, everyday tasks.

jQuery fixed both of these problems. It made it possible to write a single, concise JavaScript program that worked across all web browsers. This makes your life as a web developer so much easier, which is great. But on the other hand, jQuery is just one more thing you need to learn as a web developer, on top of all the things we’ve talked about before:

  • AJAX requests
  • The event queue
  • JSON,
  • Thinking in an asynchronous way

That’s a lot of stuff to remember and tie together. And it’s a key reason why JavaScript is so hard to learn.

6. JavaScript is so hard to learn because it seemingly violates a ton of the rules you’ve previously learned while working with a different programming language.

While the syntax seems familiar to other programming languages, the underlying mechanisms of how you need to think as a developer are often much different.

JavaScript is vastly different from languages like ruby, Python, Java, C++, and basically every other programming language that is used in the industry.

This means that picking up other languages programming languages after learning JavaScript (if it’s the only programming language you know) will be much more difficult.

It’s definitely worth your time to learn JavaScript, but it certainly shouldn’t be the first programming language you learn.

7. JavaScript is so hard to learn because  it is evolving at an ever increasing speed.  

The language itself is adapting.  And things like babel allow you to write ES6 (next-generation JavaScript) and run it using normal JavaScript runtimes. There is even experimental JavaScript stuff in ES7 that may or may not make it into the new JavaScript programming language.

This means even that even learning all of the things mentioned previously in this post, there still is more that you will probably need to learn.  

It’s easy to venture out and try to learn the latest flashy thing. After all, that’s what everyone likes to talk about.  But before you try to learn the new “hot technology” that you read about on HackerNews, make sure that you gain a solid foundation in the core JavaScript language. You should always master the fundamentals before throwing newer, even faster-evolving technologies into the mix.

So, if you’re new to coding and feeling overwhelmed by JavaScript, know that you are not alone.  

JavaScript is hard to learn. Even experienced developers face JavaScript Fatigue.

It’s not all bad. The improvements to the JavaScript language in ES6 are a fresh breath of air. They’ll eventually make it easier for beginners to hit the ground running building JavaScript programs. It’s impressive to see the progress that the JavaScript community is making to make the lives of its developers easier.

JavaScript definitely has a bright future and is worth learning. But it’s really hard to learn. So if you’re a beginner programmer and feeling intimidated by JavaScript, know that you’re not alone. I’m a fairly experienced web developer and I still have bouts of JavaScript fatigue from time to time.

Did you learn something from this post? If so, then share it using the Facebook and Twitter buttons below.

Recommended For You

4 thoughts on “Why is JavaScript so hard to learn?

  1. One of the awesome post. Really like your way of writing, explaining and love your choice of words
    One more thing i am fan of ur examples
    Such a great explaining love it
    ?Keep doing u r doing so well
    keep it up
    #Javascript lover
    “Where there is a javascript there is a way”

  2. Feeble excuses for a badly designed language. Other languages support most of the features or concepts you mention. Perhaps the real reason is that it has a monopoly. If you’re in the browser, you’re forced to use JavaScript. Note that no one uses it server-side nowadays.

    1. I get what your saying, but NodeJS is growing pretty fast and now there are a lot of people using javascript on server-side because of that.

Leave a Reply

Your email address will not be published. Required fields are marked *