Skip to content
📝 字数:working on

Booleans and Numbers

Estimated time to read: 2 minutes

Concepts

Associativity

  • Right

    • assignment (=), are right-to-left associative;

    • The exponent operator is also right-to-left associative

unary

  • exclamation mark (!)

  • bitwise NOT operator tilde (~): flips every bit, meaning it changes all 1s to 0s and all 0s to 1s.

  • void keyword is a unary operator that evaluates an expression and returns undefined. Evaluating an expression can do something, independently of the value it produces.

Bitwise Operators

  • The bitwise AND (&) operator returns a 1 in each bit position for which the corresponding bits of both operands are 1.

  • The bitwise OR (|) operator returns a 1 in each bit position for which the corresponding bits of either or both operands are 1

  • The bitwise XOR (^) operator returns a 1 in each bit position for which the corresponding bits of either, but not both, operands are 1

  • The bitwise NOT (~) operator inverts all the bits of its operand.

  • The left shift (<<) operator shifts all bits to the left by a specified number of positions.

  • The right shift (>>) operator shifts all bits to the right.

The nullish coalescing operator

Represented by a double question mark (??), it helps in scenarios where you want to return a value only if the first one is null or undefined

why null >= 0 ?

Expression Result Reason
null >= 0 true Numeric comparison: null becomes 0
null > 0 false 0 is not greater than 0
null == 0 false Loose equality does not convert null to a number here
null === 0 false Different types

评论