DEV Community

pranavinu
pranavinu

Posted on

Opreator in JS

Operator

1)It performs operation on variables and values

Arithmetic operator:

1)It performs an operation like(add,sub,..etc)

Add operator:

It is to add two values

let a=10;
let b=20;
console.log(a+b);

Concatenation:

Joining the strings a with another (string or values)

let e="5"
console.log("Enter the number "+e);

Subract:

It is to subract two values

let c=10;
let d=20;
console.log(c-d);

type casting:

Converts a value from one data type to another datatype,(string to number)

let i=10;
let s="20";
console.log(i-s);

Multiplication:

1)it is to multiple the two values

let c=10;
let d=20;
console.log(c*d);

Division:

It gives a quotient

let c=10;
let d=20;
console.log(c/d);

Modulus:

It gives a reminder

let c=10;
let d=20;
console.log(c%d);

Exponential:

It rises the left value to the power of the right value

let c=2;
let d=3;
console.log(c**d);

Assignment operator:

It is to assign the values to the variable

let d=20;
console.log(d);

Comparison operator:

1)It is to compare the two values
2)It returns a boolean values

Equality:

It is to check the values are same

let i=2;
let s=3;
console.log(i==s);

Strict equality operator:

It is to check the values are same and has a same datatype

let i=2;
let s="3";
console.log(i===s);

Inequality operator:

It is to check the values are not same

let i=2;
let s=3;
console.log(i!=s);

Strict inequality operator:

It is to check the values are not same or not of the same datatype

let i=2;
let s="3";
console.log(i!==s);

Less than operator:

It is to check if the left value is less than the right value

let i=2;
let s=3;
console.log(i<s);

Greater than operator:

It is to check if the left value is greater then the right value

let i=2;
let s=3;
console.log(i>s);

Less than or equal to operator:

It is to check if the left value is less than or equal to the right value

let i=2;
let s=3;
console.log(i<=s);

Greater than or equal to operator:

It is to check if the left value is greater then or equal to the right value

let i=2;
let s=3;
console.log(i>=s);

post-Increment:

It return the value first and then it gets incremented

let h=12;
console.log(h++);
console.log(h);

pre-Increment:

It increments the value first and then it returns the value

let h=12;
console.log(++h);

post-Decrement:

It return the value first and then it gets decremented

let h=12;
console.log(h--);
console.log(h);

pre-Decrement:

It decrement the value first and then it returns the value

let h=12;
console.log(--h);

let i=5;
let j=10;
let result =--i - --j - j-- + ++j;
console.log("result"+result);

output:-5

Top comments (0)