-2

I have seen that typescript often modify the original JavaScript operators to create their own operators. Why does this really happen?

The same doubt I have with the operator "or logical assignment '|'"

Justin Castillo
  • 95
  • 1
  • 1
  • 5
  • 5
    There is no `!!` operator. That's two applications of the `!` operator. Doing that converts a value of any type to a boolean according to the normal JavaScript "truthy/falsy" rules. – Pointy Aug 22 '17 at 14:37
  • 1
    What Pointy said. `||`, on the other hand, is a different operator from `|`. – Sergio Tulentsev Aug 22 '17 at 14:37
  • @Pointy [to add more reference](https://stackoverflow.com/questions/784929/what-is-the-not-not-operator-in-javascript) – George Aug 22 '17 at 14:38
  • @George oh thanks, I was looking for that. However because of the `|` vs `||` question it's more like a duplicate of two different bugs. – Pointy Aug 22 '17 at 14:39
  • *"I have seen that typescript often modify the original JavaScript operators to create their own operators."* I don't think TypeScript has any operators of its own other than `<>` and `as` for casting. – T.J. Crowder Aug 22 '17 at 14:39
  • @Pointy yeah I thought that as well, otherwise it'd be a close flag from me. – George Aug 22 '17 at 14:39
  • Typescript does add a final `!`, used to indicate an otherwise nullable value is not null, but no `!!` operator. – ssube Aug 22 '17 at 14:40

1 Answers1

1

'!!' operator is the same as '!' in TypeScript?

No. There is no !! operator.

!! is just two JavaScript ! operators in sequence.

The same doubt I have with the operator "or logical assignment '|'"

There is | called Bitwise OR : https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Bitwise_OR

There is || called Logical OR : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators#Logical_OR

Again they are the same as JavaScript

basarat
  • 261,912
  • 58
  • 460
  • 511