![]() |
JavaScript operators like logical OR (||), logical AND (&&), and null coalescing (??) are used for making conditional evaluations and performing logical operations in JavaScript. While these operators are commonly used for controlling the flow of the code execution and handling values in the different scenarios it’s essential to understand how they behave in terms of comparison and evaluation. We will discuss different approaches of JavaScript operators like or ( || ), and ( && ), null coalescing ( ?? ) makes a weak comparison: Weak Comparison with Logical Operators (|| and &&)The logical OR (||) and logical AND (&&) operators in JavaScript perform the weak comparison. The Weak comparison means that the operands are coerced to the boolean values before being evaluated. In the case of the logical OR (||) if any of the operands evaluates to true the result is true. Similarly in the case of the logical AND (&&) if all operands evaluate to the true the result is true. Syntax:// Logical OR (||) operator Example: Below is an of JavaScript operators Weak comparison with Logical Operators (|| and &&):
Output: 5 Null Coalescing Operator (??)The null coalescing operator (??) is used to the provide a default value for the nullable values. It returns the right-hand operand when the left-hand operand is null or undefined; otherwise, it returns the left-hand operand. Syntax:result = operand1 ?? operand2; Example: Below is an example of JavaScript Operators of Null Coalescing Operator (??):
Output: default |
Reffered: https://www.geeksforgeeks.org
JavaScript |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 15 |