User Tools

Site Tools


java-script:bitwise-or-bitwise-and-ternary-optional-chaining-operators

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
java-script:bitwise-or-bitwise-and-ternary-optional-chaining-operators [2023/08/10 04:26] odeftajava-script:bitwise-or-bitwise-and-ternary-optional-chaining-operators [2023/08/11 13:19] (current) odefta
Line 1: Line 1:
-====== Java Script | Bitwise OR, & Bitwise AND, ? Ternary Conditional Operator and ?. Optional Chaining Operator ======+====== Java Script | Bitwise OR, ^ Bitwise XOR, & Bitwise AND, ? Ternary Conditional Operator and ?. Optional Chaining Operator ======
  
 In JavaScript, there are the **| (bitwise OR)** and **& (bitwise AND)** operators, which are different from **||** and **&&**. These operators perform bitwise operations, which means **they operate on the binary representations of numbers**. In JavaScript, there are the **| (bitwise OR)** and **& (bitwise AND)** operators, which are different from **||** and **&&**. These operators perform bitwise operations, which means **they operate on the binary representations of numbers**.
  
-===== | (Bitwise OR=====+===== | Bitwise OR =====
  
 The **|** operator returns a value where each bit is set if the corresponding bit is set in **either** of the two operands: The **|** operator returns a value where each bit is set if the corresponding bit is set in **either** of the two operands:
Line 12: Line 12:
 </code> </code>
  
-===== (Bitwise AND=====+===== ^ Bitwise XOR ===== 
 + 
 +The ^ XOR (exclusive or) operation returns true if exactly one of the bits being compared is true: 
 +<code javascript> 
 +let a = 5; // binary: 0101 
 +let b = 3; // binary: 0011 
 + 
 +let result = a ^ b; // binary: 0110, decimal: 6 
 + 
 +</code> 
 + 
 +===== & Bitwise AND =====
  
 The **&** operator returns a value where each bit is set if the corresponding bit is set in **both** operands: The **&** operator returns a value where each bit is set if the corresponding bit is set in **both** operands:
Line 29: Line 40:
 </note> </note>
  
-===== ? (Ternary Conditional Operator=====+===== ? Ternary Conditional Operator =====
  
 The ternary conditional operator is a concise way to perform a conditional (if-else-like) operation. \\  The ternary conditional operator is a concise way to perform a conditional (if-else-like) operation. \\ 
Line 44: Line 55:
 </code> </code>
  
-===== ?. (Optional Chaining Operator=====+===== ?. Optional Chaining Operator =====
  
 Introduced in ECMAScript 2020, the optional chaining operator **?.** allows you to access properties of objects without having to check if the object or property exists. If the object or property doesn't exist, the expression **short-circuits** and returns undefined. \\  Introduced in ECMAScript 2020, the optional chaining operator **?.** allows you to access properties of objects without having to check if the object or property exists. If the object or property doesn't exist, the expression **short-circuits** and returns undefined. \\ 
java-script/bitwise-or-bitwise-and-ternary-optional-chaining-operators.1691630813.txt.gz · Last modified: 2023/08/10 04:26 by odefta