Blog post cover
Arek Nawo
18 Nov 2019
11 min read

Why you should learn how to code and do so with JavaScript?

So, here, on my blog, I usually write about all sorts of programming-related topics. When creating my posts, I assume that the reader possesses the required level of programming knowledge, except for the discussed topic. But, I know that many are just getting started and don’t have any knowledge about the subject. So, if you’re one of those people - the following piece is dedicated solely to you.

In this and a few upcoming articles, I’ll teach you how to code in JavaScript. I’ll try to explain everything gradually, in detail, without any prior knowledge required. You just have to know what’s ahead of you and how to use a computer. :)

Today, we’ll start by exploring some more general terminology and concepts used in general programming, while focusing mainly on JavaScript. We’ll also analyze some facts related to programming and how you could benefit from learning it, only to help you stay motivated in this not to say short journey. All of this will help you better understand the topic, and write your first piece of code. Now, let’s get started!

JavaScript

JavaScript (JS - not to be confused with Java) is a programming language created more than 20 years ago. While I won’t bother you with history here, the fun fact is that its prototype was created by Brendan Eich in just 10 days! Some people mention it only to point out how unstable and straight-up bad the JS is. You shouldn’t care about such opinions too much. Even if JS has some quirks hidden in its sleeve, it’s still a very solid language and was improved quite a lot since its creation.

Use-cases

How can JS reliability be proven, you ask? Well, it’s powering the enormous World Wide Web (WWW) after all. Alongside HTML (a markup language used to create website layouts) and CSS (a style sheet language used to stylize website elements), it’s the core technology behind WWW and thus, the web development as a whole.

Because “web development” is a term that you’ll certainly hear a lot of times, I think it requires some further explanation. It refers to all the code-related aspects of a website creation process. So, not necessarily design, but rather it’s implementation. Which, on the other hand, refers to bringing some ideas or concepts into life (with code). I’m not providing some raw definitions here - you have Wikipedia for that. ;) I just want you to get a grasp of what it’s all about.

So, JS is used to make websites. To be a little more specific, it’s powering almost all interactive functionalities that you can find the web… and more! To know its significance, go to your browser’s settings and find the toggle to disable it - there has to be one. On Chrome, you can do this by going into the settings menu of a website (e.g. by clicking the lock icon next to the website’s name) and disabling JS from there. You’ll see just how much JS is responsible for on the per-website basis.

Beyond WWW

For a long time, JS stayed on the web and did nothing more. But, a project named Node.js (in JS space many projects have the .js ending) changed that. To keep it simple, it allowed JS to be run not only in the browser but also on the server. What it means is that from that point on JS can be used to perform tasks like managing databases, processing and sending data, etc. - basically server stuff.

Node.js wasn’t the only project that changed the way JS is used. Other projects, like Electron, or NativeScript have allowed it to be run not only in the browser or on the server, but also in the full-fledged mobile and desktop apps! Hence the popular phrase - “JavaScript is everywhere!”. It powers websites you visit every day - from Facebook to Twitter and Google. Through Node.js, it partially powers the back-end of giant companies like Microsoft, Netflix or PayPal. And finally, you may use desktop Spotify or mobile Instagram or Pinterest app - also powered by JS.

Quick explanation. I used the term “back-end” up there. To simplify a little, it’s a different word for “all thing server”. “Front-end”, on the other hand, refers to the website or an app itself - the thing the user sees and interacts with. I think you get the difference.

Under the hood

Now, that I’ve impressed you enough with JS and its potential, let’s talk for real! Let’s start with a simple fact - JavaScript is a high-level, dynamically and weakly-typed, prototype-based, multi-paradigm, and interpreted programming language. Now I’ve got you! Problem is always easier to solve when you break it into smaller chunks. That’s one of the most important principles of problem-solving - probably the most important thing to learn in programming. Let’s try that, shall we?

High-level

Nowadays, most of the used programming languages are considered high-level. What it means is that the language utilizes all the high-level structures like variables, functions or objects (we’ll discuss all of that in the future). Such a language has simple and understandable syntax (something like grammar in usual languages), that seems somewhat familiar to languages that we speak - just see:

function sayHello() {
	console.log("Hello!");
}
sayHello();

On the other side of the spectrum, we have low-level languages. They are closer to machine code (aka 0s and 1s) and thus less-friendly to the programmer. The best example of such a language is the Assembly. When using it, you may not code directly in machine code, but you must use processor instructions, registers and all that kind of complex, “close to bare metal” stuff. As JS is a high-level language, we don’t have to understand all of this to start programming. However doing so, makes us better at it.

Abstractions

High-level programming languages favor an intensive use of abstractions. Abstraction takes place when e.g. a processor instruction is expressed with a short word or abbreviation instead of a set of 0s and 1s (Assembly), or, when going even further, using human-readable syntax. Like in JS.

Dynamic and weak typing, prototypes, programming paradigms are all just different kinds of abstractions and concepts. But, as some programming knowledge is required, to understand everything, we’ll skip them for now. We’ll come back to them once you’ll have the proper knowledge of JS, later in this series. But, if you want to do this now, you can read one of my previous articles - complex stuff incoming!

Compiled vs interpreted

The last fact that we need to examine is that JS is an interpreted programming language… even if that’s only somewhat true…

If we had seen the world in black and white colors, we’d have said that there are only 2 kinds of languages - compiled and interpreted ones. Compiled programming languages are the ones that have the code written in them compiled (aka processed) down to machine code, through a tool called compilator. Compilation gets rid of all the introduced abstractions and leaves us with raw machine code that then can be later executed directly on the user’s machine.

Interpreted languages, on the other hand, have their code executed by another program. It’s called an interpreter. It takes all your code and executes it right away. It simply “understands” and executes the provided instructions. However, the interpreter still needs to somehow work, so itself, it can either be compiled or (ironically) interpreted by yet another interpreter.

Just from logical thinking, you should be able to deduce that compiled programs run faster than the interpreted ones. They’re simply “closer to the metal”. Thus, the rule of thumb is the more abstraction the easier (and faster) the programming process, but the slower the resulting program. Compiling code reduces that impact, but it still won’t be faster than a well-written Assembly code. However, writing pretty much any somewhat complex app in Assembly would be a nightmare! It’s yet another job of the programmer to find the right balance between abstraction and performance.

JS has been an interpreted language for a long time. However, things have changed a little with the rise of Node.js and in the process of language development. Chrome’s open-source (whose code is accessible freely to everyone) JS engine - V8 -  introduced what’s called Just In Time (JIT) compilation. What it means is that JavaScript code is still run like if it was simply interpreted, but some parts of it (the most optimized and repetitive ones) are compiled in the background to make their execution faster. It’s a very neat concept that essentially improves the performance of the code without any programmer action required. You can learn more about it here.

Specs

So, as I said, Chrome has it’s own JS engine. It not only contains the interpreter and JIT compilator but also other functionalities related to the language. And bear in mind - other web browsers like Firefox and Safari also have their own JS engines. How can one maintain compatibility between so many different implementations?

The answer is ECMAScript (ES). It’s an official JavaScript specification that all implementations of JS have to follow. Without it, we’d be lost in compatibility chaos. Any of JS’ portability advantages would be gone and WWW wouldn’t be as nice of a place as we currently know it.

ES dictates the speed of JS development. It had its ups and downs, but ever since 2015 with the introduction of ECMAScript 6 (which came with a much-needed set of new features), a new version is published every year (usually around June), with the latest version being *ES10*/ES2019. For more in-depth info about the whole ECMAScript thing, you can check out this blog post.

Web APIs

While the JS language itself follows the ES specs, some things don’t. The set of Web APIs is a good example. Application Programming Interface, or API for short, is an abstraction that gives developers easier access to complex functionalities. Browsers provide such APIs (called Web APIs) to provide functionalities like audio (Web Audio API) or 3D graphics (WebGL).

Here, I’d like to return to Node.js for a moment. Under the hood, it uses Chrome’s V8 engine - mainly for its performance. It also follows the ES specification (it uses JS after all). But, it doesn’t implement Web APIs. Maybe it’s somewhat logical - after all Node.js doesn’t work on the web. To counter the losses, Node.js has its own set of APIs. However, they have different functionalities when compared to Web APIs. For example, they allow the programmer to access the detailed operating system and hardware-related info - something that you shouldn’t have access to through the browser.

Money & career

To top it all off, let’s talk about money - it’s a motivation article after all, right? So, let’s put programming knowledge aside and discuss something nicer

Because of JavaScript’s increasing popularity (it’s one of the most popular programming languages in the world), there’re many job opportunities available. In the US, the salary of a JS developer often exceeds 100 000$. The situation in other countries also looks pretty nice.

Apart from usual jobs, JavaScript is a great choice for freelancers, who want to work on their own. It’s also a great language to create your very own product. There’re many success stories of JS apps that made their authors millions. JS also has a vivid open-source community. Believe it or not, you can make a career even by working on free code. In programming, pretty much the only limitation is your imagination… and hardware.

The journey begins…

I hope I managed to get you at least somewhat interested in programming. If so, then follow me on Twitter, Facebook, Reddit, or through my weekly newsletter to learn and talk JS. In doing so, you won’t miss the second part of this series, where we’ll be discussing the basic JS constructs and how they interact together to form something incredible! You can also share this post with your friends, who may also be interested in learning how to code. It’s an awesome journey that you might want to get through together.

If you have any programming questions, hit me up in the comments section below, or even better - on the Reddit community page. I’ve also started a YouTube channel, so check it out and subscribe if you want to learn about some interesting JS facts or watch some Tutorials (more coming soon). As always, thank you for reading this piece and I wish you a happy day!

If you need

Custom Web App

I can help you get your next project, from idea to reality.

© 2024 Arek Nawo Ideas