Introduction: The Assignment operator

JavaScript, as well as most other programming languages, contains a lot of different operators. Most of the operators you'll recognize because they are not made up of letters, but instead one or several special characters. In this tutorial, I'll try to introduce you to all of them, from the simple ones, like the assignment operator which we'll look into in this article, to the more advanced ones.

To kick things off, let's start with the assignment operator. It's one of the simplest and most commonly used operators in JavaScript. In fact, it's so common that we have already used it several times in this tutorial without discussing it - we simply can't accomplish much without it.

The simple assignment operator

In JavaScript, as well as in a lot of other programming languages, you can assign a value using the equality sign: =

It's sometimes referred to as the simple assignment operator, but think more of it as the "I'll use this ALL the time"-operator, because programming is all about assigning values. We already used it several times in this tutorial, but to refresh your memory, this is how it looks when you use the assignment operator in JavaScript:

let helloWorld = "Hello, world!";

Right in the middle we have the equality sign, which in this case tells the interpreter that the variable, called "helloWorld", should now contain the text string "Hello, world!".

However, the assignment operator isn't just used when declaring a variable, but also when you want to change the value of this variable later on:

let helloWorld = "Hello, world!";
helloWorld = "Hello, universe!";


This was a brief introduction to operators in general and the simple assignment operator specifically. There are other ways of assigning values, e.g. the addition assignment operator, but we'll get to that in one of the coming articles.

This article has been fully translated into the following languages: Is your preferred language not on the list? Click here to help us translate this article into your language!