JavaScript Operators
JavaScript operators are symbols or keywords used to perform operations on values and variables. They are the building blocks of JavaScript expressions and can manipulate data in various ways.
1.Arithmetic Operators
Arithmetic Operators perform mathematical calculations like addition, subtraction, multiplication, etc.
let a=5+2;
let b=8-5;
let c=3*2;
let d=9/3;
console.log(a,b,c,d);
Output:7 3 6 3
2.Assignment Operators
let n=10;
n+=5; //n=n+5
n*=2; //n=n*2
console.log(n);
Output:30
in this,
- = assigns a value to a variable.
- += adds and assigns the result to the variable.
- *= multiplies and assigns the result to the variable.
3.Comparison Operator
Comparison operators compare two values and return a boolean (true or false).
console.log(10 > 5);
console.log(10 === "10");
Output: true
false
- > checks if the left value is greater than the right.
- === checks for strict equality (both type and value).
- Other operators include <, <=, >=, and !==.
4.Logical Operators
Logical operators are used to determine the logic between variables or values.
let a=10;
let b=2;
console.log(a && b || b!=a);
Output: True
Top comments (0)