JavaScript Operators
Operators are the symbols that perform any specific operation.
As you Know in Mathematics when you have to add 2 numbers then you have to use (+) addition operator in between numbers to add them.
Same thing happens in Javascript.
There are Many Types of Operators.
- Arithmetic Operators
- Assignment Operators
- String Operators
- Comparison Operators
- Logical Operators
- Type Operators
- Bitwise Operators
var x = 59;
var y = x % 5;
console.log(y);
Note :
Here,
x has the value of 59
y has the value of x % 5 i.e 59 % 5
59 % 5 ⇒ when 59 is divided by 5 its gives quotient 11 and remainder 4
So, value of y will be 4 i.e remainder
console.log(y) will print the value of y in console tab.
var x = 50;
x += 5;
console.log(x);
Note :
Here,
x has the value of 50
x : x += 5 i.e x = 50 + 5
So, value of x will be 55
console.log(x) will print the value of x in console tab.
String Operators
We use String operators to perform actions on String.
Example 1 :
var firstName ="java";
var lastName = "script";
var fullName = firstName + lastName;
console.log(fullName);
Here,
fullName is firstName + lastName
i.e. fullName is "java" + "script"
Output will be "javascript"
Example 2 :
var string ="Hello ";
var string2 = "World";
string += string2;
console.log(string);
Here,
string is "Hello " and string2 = " World"
string = string + string2
i.e. string is "Hello " + "World"
Output will be "Hello World"
Note :
You can also add numbers to the string
For Example :
var name = "Javascript";
var age = 25;
var description = "Hi my name is " + name + " and i am " + age + " years old.";
console.log(description);
Here,
Output will be : "Hi my name is Javascript and i am 25 years old."
We will be Studing about Comparison, Logical, Type and Bitwise Operators in their Respective Chapters.