DEV Community

Mamadou Aliou Diallo
Mamadou Aliou Diallo

Posted on • Originally published at kaherecode.com

Learn Javascript: Introduction

So are you new to programming or are you just trying to learn Javascript to add it to your other skills? Welcome! This series of tutorials is for you and you just have one thing to do, practice what we will see together. I will never stop saying it, it is useless to read tutorials without practice, the only way to really learn to program is to practice.

In this tutorial, we will discover what is Javascript, it’s different versions, and see the basics to code in Javascript. Let’s start now.

This tutorial is the first in a series of tutorials I write about programming in Javascript, be sure to follow to not miss any of the next tutorials.

Javascript is one of the most popular programming languages, it is now used in almost all areas related to programming: Web, Mobile, Desktop Software, Embedded Systems, Machine Learning, Video Games, …

Javascript is now used to create full stack web applications (front end and back end). The rise of Node.js in recent years has opened the use of Javascript on the back end, which came under the domain of languages such as Java, Python, PHP, Ruby, … But what is Javascript?

Javascript, what it is?

Created 20 years ago, Javascript was the first and only scripting language supported by web browsers. It was mainly used to make animations on DHTML pages.

Nowadays, JavaScript has evolved and executed as we saw in the introduction on the front end (on the browser) but also in the back end (on the server), so what started as a simple language of scripts running in a browser has become a global language used almost everywhere. Javascript will run on any hardware that contains a so-called Javascript engine, there are several including V8 at Google Chrome and Opera, SpiderMonkey at Firefox, SquirrelFish at Safari, … It is these engines that read the Javascript and execute it.

To define Javascript in a few points, we will say that Javascript is:

  • a high-level language: it does not provide low-level access to memory or the CPU, as it was originally created for browsers that do not need it.
  • a dynamic language: a dynamic language executes at the moment of the execution of many tasks that a static language carries out at the compilation. This has advantages and disadvantages and gives us powerful features such as dynamic typing, late binding, reflection, functional programming, changing the execution of the object, and so on.
  • a dynamically typed language: in Javascript, a variable does not necessarily have a predefined type. So we can change the type of a variable during program execution.
  • a weakly typed language: as opposed to strong typing, weakly typed languages do not impose the type of an object, which allows more flexibility, but denies us security and type checking (something that TypeScript and Flow aim to improve)
  • an interpreted language: It is commonly called an interpreted language, which means that it does not require a compilation step before the program can be executed, unlike C or Java, for example. In practice, the browsers compile Javascript before executing it, for performance reasons, but this is transparent for you: no additional step is necessary.
  • a multi-paradigm language: the language does not apply a particular programming paradigm, unlike Java, for example, which imposes the use of object-oriented programming or C that imposes imperative programming. You can write Javascript using an object-oriented paradigm, using prototypes and the new class syntax (from ES6). You can write Javascript in a functional programming style, with its first class functions, or even in imperative style (like C).

Let’s do a little set up, Javascript has nothing to do with Java. Java is a programming language from Sun Microsystems, and Javascript a language developed by Brendan Eich.

For the little story , the first version of Javascript was called LiveScript, but Java already existed at the time and was already very popular, the JavaScript maintainers have thought that positioning their language as the little brother of Java could help to position the language well, so they called it JavaScript.

But today all this has changed, Javascript has its own specification called ECMAScript that we will see earlier.

Versions of Javascript

Now let’s talk about ECMAScript, that weird name. ECMAScript (also called ES) is the standard on which Javascript is based.

Ecma International is a Swiss Standards Association responsible for defining international standards.

The first version of Javascript (LiveScript) in 1997 was called ES1, then ES2 and ES3 in 1998 and 1999. Then came out ES4 which was a real fiasco and had to be abandoned (thanks Wikipedia).

In December 2009 came out ES5 then ES5.1 in June 2011.

In June 2015, Javascript has undergone a major change, the ES2015 is out, the change is already visible on the name. The official name is now ES2015 and the edition is ES6, today we will find more ES6 as the name than ES2015, but that does not change anything. This version of Javascript brings major changes to programming in Javascript such as classes, generators, … Since each year, in June, a new version of Javascript is published.

  • ES2016 (ES7)
  • ES2017 (ES8)
  • ES2018 (ES9)

Well, for the edition, you just take the last digit of the official name (ES2017–7) and you add 1 (ES7 + 1 — ES8), the version of Javascript that will be released this year in 2019 (June) will be called ES2019 and the edition will be ES10 (ES9 + 1).

Utilities of Javascript

Since the beginning of this tutorial, I keep saying it, Javascript is today used in almost all the domains of the computer programming that we know, web development, mobile development, video games , machine learning, …

Let’s talk here about the two most popular areas, namely web and mobile development.

On the web, Javascript allows us today to make full stack applications, our application will be fully coded in Javascript on the front end and the back end, which is already extraordinary in itself. Basically, we use a back end language such as Java, PHP, Python and on the front end, well we use Javascript, which makes us two languages on one and the same application.

Always on the web, Javascript will allow us:

  • to do things on the browser of the user without having to make a request to the server (which requires reloading the page), which is good for example to validate a form
  • add HTML dynamically, edit the page content, change the style of the page following the actions of the users
  • make animations on the page

Nowadays, it is impossible to see a web page that does not use Javascript.

Now on the mobile, Javascript allows us today to make mobile applications for Android, but also iOS, with a single code base, we have our applications, no need to make Java for Android and Swift for iOS .

Javascript is therefore very used, today the mobile applications of Facebook (Messenger, Instagram, …) all turn on Javascript.

Let’s look at some syntactical Javascript styles.

The semicolon

In Javascript, the semicolon is not mandatory at all, besides personally I prefer to omit it and you will see it in the examples that we will see together. You just have to be very careful in this case, avoid, for example, writing a single instruction on several lines:

return 
1+4

Or to start a line with [ or ( and you will be saved in most cases.) Use an linter (ESLint) to report errors and nothing will happen to you seriously.

Comments

In Javascript, you can use two types of comments, comments on several lines:

/*
This is a comment in several lines
*/

and comments on one line:

// This is a comment in one line

Case sensitivity

Javascript is case-sensitive, which means that variable is different from Variable which is also different from VARIABLE.

What is important to remember is that Javascript is a very popular language today and if you have the time to learn it, do not hesitate.

It’s over for this first part, see you next for the second part of this series on Javascript, we’ll see variables and data types in Javascript.

See you soon.

Top comments (0)