Learn JavaScript With Me-IV
Operators in JavaScript(JS)
Day -4 of the javascript series & today we’ll be learning about Operators
if you are new to this series check the previous part — (link)
Since programming is all about talking to the computer, it requires building logic for everything you do.
Operators help us to build that logic quickly. They allow us to manipulate the data and perform the necessary tasks.
Operators are symbols to perform specific operations on operants. The entities on which you perform operations are operants.
Here plus(+) symbol is performing an addition operation on the value in the variable a and b and storing their result in a variable named c
JavaScript Operator Types
Here is a list of different operators you will learn in this tutorial.
- Arithmetic operators
Arithmetic operators are used to performing arithmetic calculations. For example,
const number = 3 + 5; // 8
Here, the +
operator is used to add two operands.
2. Assignment operators
Assignment operators are used to assigning values to variables. For example,
const x = 5;
Here, the =
operator is used to assigning value 5
to variable x
.
Here’s a list of commonly used assignment operators:
3. Comparison Operators
Comparison operators compare two values and return a boolean value, either true
or false
. For example,
const a = 3, b = 2;
console.log(a > b); // true
Here, the comparison operator >
is used to compare whether a is greater than b.
4. Logical Operators
Logical operators perform logical operations and return a boolean value, either true
or false
. For example,
const x = 5, y = 3;
(x < 6) && (y < 5); // true
Here, &&
is the logical operator AND. Since both x < 6
and y < 5
are true
, the result is true
.
5. String Operators
In JavaScript, you can also use the +
operator to concatenate (join) two or more strings.
Output:-
helloworld
JavaScript tutorial
6. Ternary Operators
Assigns a value to a variable based on condition & is an alternative to if-else
?:
7. Bitwise Operators
Bitwise operators perform operations on binary representations of numbers.