operator in Java/Python/Go/Javascript

Operator Java Go Python Javascript
++, – statement not statement, expression N/A supported
logical &,|,&&,||,! &&,||,! and, or, not &&,||,!
bitwise not ~x ^x ~x ~x
bitwise and x & y x & y x & y x & y
bitwise or x | y x | y x | y x | y
bitwise exclusive or x ^ y x ^ y x ^ y x ^ y
bitwise clear (and not) N/A &^ N/A N/A
?: (ternary op) supported N/A N/A supported
  • Java: &, | also have the logical function. But it differents with &&, || which have short circuiting function.
  • javascript special operator
    • instanceof: Test object class
    • in: Test whether property exists, prop in objectName
      • in object: test property whether in object
      • ** in array**: test index (not element) whether in array
        1. 1
        2. 2
        3. 3
        4. 4
        5. 5
        1. var testInArray = [7, 8, 9];
        2. "0" in testInArray; // true
        3. 1 in testInArray; // true
        4. "7" in testInArray; // false
        5. 8 in testInArray; // false
    • delete: Remove a property
    • typeof: Determine type of operand
    • void: return undefined value
    • >>>: Shift right with zero extension
    • ===, !== : Test for strict equality/inequality, type and value should be tested.
    • !!x: get equality of boolean of x
  • go
    • ++, –: only supports post increment/decrement
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  1. /*** java ***/
  2. Int demoInt2 = demoInt1++
  3. ++demoInt1
  4. - x ==y, x != y // value equals or not
  5. - x.equals(y) // same object
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  1. ### python ###
  2. >>>a**b == pow(a, b)
  3. >>>(a//b, a%b) == (a//b, a%b) == divmod(a, b)
  4. >>> x == y, x !=y # value equals or not, check __eq__
  5. >>> x is y, x is not y # same object or not, check pointer
  6. x in y, x not in y
  7. >>> abs(-5) == 5
  8. True
  9. >>> a = 2
  10. >>> ~a
  11. >>> from struct import pack
  12. >>> pack('b', -1)
  13. '\xff'
  14. # build-in function for sequence, dict
  15. min(), max(), sum(), cmp()
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  1. /*** go ***/
  2. demoInt2 := demoInt1++ // syntax error
  3. ++demoInt1 //syntax error
  4. x := 2
  5. x, ^x // 0010 -> 1101 -> (1101 -1) -> 1100 -> 1011
Powered By Valine
v1.5.2