JavaScript Operators
JavaScript have different types of operators, first let’s talk about Logical Operators. JavaScript supports three logical operators: and,or and not. This operators area applied to Boolean values for example
console.log(true && false); // -> && and operator
//output -> false
console.log(true && true);
//output -> true
Like we can see, to get a true output both values have to be true, if one of them is false, the output will be false. For other to get a true output with the or operator, we just need one true value.
console.log(false || true); // -> || or operator
//output -> true
console.log(false || false);
//output -> false
The last operator is not, this operator flips the value of given to it
console.log(!true) // -> ! not operator
//output -> false
Unary Operators
A unary operator is one that takes a single operand/argument and performs an operation.
This is a list of unary operators
Ternary operator
An special operator who is used like a short if statement, let’s see:
//If statement
if(true){
console.log("hola");
}else{
console.log("mundo");
}
//output -> hola//Ternary operator
true ? console.log("hola") : console.log("mundo")
//output -> hole
We also have the spread operator, this one is used to destructuring objects and arrays, for example
const arrayOne = [1,2,3];
const arrayTwo = [4,5,6];
const fullArray = [...arrayOne,...arrayTwo];
console.log(fullArray);
//output -> [1,2,3,4,5,6]
Get more info https://eloquentjavascript.net/01_values.html