2 min read
The Arithmetic operator includes subtraction -, addition +, multiplication *, division /, and Remainder operator. %. They are mostly used with number and string types.
The addition operator can be used to concatenate strings,
let firstName = 'Ned'; let lastName = 'Stark; let fullName = firstName + lastName; // Ned Stark
The rest work with number types
console.log(3 + 5); // expected output: 8 console.log(8 - 8); // expected output: 0 console.log(3 * 5); // expected output: 15 console.log(8/2); // expected output: 4
The Logical Operators are OR ||, AND assignment &&, Nullish operator ??.
The OR operator (||) has multiple operands and returns the right operand if the left operand is false, otherwise it returns its right operand.
const title = '' console.log(title || 'comissioner'); // expected output: comissioner
The AND operator (&&) takes multiple boolean operands and will be true if and only if all the operands are true. Else, it will be false.
console.log(true && true && false); // expected output: false console.log(true && true && true); // expected output: true
The nullish coalescing operator ?? returns its right operand if its left operand is null or undefined, and otherwise returns its left operand.
console.log(null ?? 'random stuff'); // expected output: "default string" console.log( 0 ?? 4); // expected output: 0
In this article, you were re-introduced to arithmetic and logical operators. This article provides a mental break from all of the technical stuff you've been reading recently.