Sitemap

Operators in JavaScript

2 min readJan 4, 2024

--

Hey, dev community!! how are you all? I hope you all are fine and enjoying the series of javascript so let us continue in the previous blog we are reading operators and now continue to another type of operators…

so here we discuss some more types of operators.

String Operator: In addition to the comparison operators, which can be used on string values, the concatenation operator (+) concatenates two string values together, returning another string that is the union of the two operand strings.

console.log("my " + "string"); // console logs the string "my string".

Conditional Operator:-The conditional (ternary) operator is the only JavaScript operator that takes three operands: a condition followed by a question mark (?), then an expression to execute if the condition is true followed by a colon (:), and finally the expression to execute if the condition is falsy.

//Syntax
//condition? True: False

//For example
const age = 26;
const beverage = age >= 21 ? "adult": "child";
console.log(beverage);

many times we make a chain of if, else conditions so this makes our code messy for example

x = 10

if x < 0:
print("x is negative")
elif x == 0:
print("x is zero")
elif x < 10:
print("x is positive but less than 10")
else:
print("x is 10 or greater")

so this makes our code messy and lengthy,here we used or replaced it with conditional chaining,

Get Palak Gupta’s stories in your inbox

Join Medium for free to get updates from this writer.

conditional chaining example:

function example() {
return condition1 ? value1
: condition2 ? value2
: condition3 ? value3
: value4;
} //like this,

Comma operator:-The comma (,) operator evaluates each of its operands (from left to right) and returns the value of the last operand. for example


x = (67, 3);
console.log(x);
// Expected output: 3

Grouping Operator:- the grouping operator consists of a pair of parentheses around an expression or sub-expression to override the normal operator precedence so that expressions with lower precedence can be evaluated before an expression with higher priority. This operator can only contain expressions. The parameter list is passed to a function within this operator which will treat it as an expression.

const a = 1;
const b = 2;
const c = 3;
a + b * c; // 7

so you know there is one additional thing in the arrow function we use grouping operators and it gives us return value for example.

const fun=()=>{
return(
console.log("hello dev")
)
}
fun()

So thank you dev for reading we will meet in our next blog. and for more such blog notifications pls subscribe to my profile.

--

--

Palak Gupta
Palak Gupta

Written by Palak Gupta

i am pursuing my second sem in MCA from MITS college and want to become Software Developer.