Operators in JavaScript are very useful and important. They can do all kinds of things and take many different forms. There are a few different families of operators in JavaScript, but today we will focus on those most useful for web development.

In this article, we will explore some useful operators in JavaScript with practical examples. Let’s get right into it.

1. Assignment Operators

The assignment operator **=** is one of the basic operators you must know in JavaScript. Assignment operators assign the value on their right side to their left side. Besides( = ), there are a number of assignment operators that are useful shorthand.

Have a look at the example below:

// Assign a value to a new variable
var variable = 0;

// Shorthand to increase variable's value by 1
variable += 2;
// Shorthand to decrease the variable's value by 1
variable -= 1;
// Our variable is at 1
console.log(variable);

// Shorthand to multiply a value into variable
variable *= 2;
// Shorthand to divide variable by value
variable /= 2;
// Our variable is at 1
console.log(variable);

These shorthand assignment operators save us from having to write the variable two times. For example, instead of writing variable = variable +1 , we can write variable += 1 or variable++ .

#web-development #javascript-tips #javascript #coding #programming

6  Useful JavaScript Operators that You Should Know
1.75 GEEK