3

I have seen null ! many times in source code of Angular. What's the meaning of the following ! mark?

examples:

Yishu Fang
  • 9,448
  • 21
  • 65
  • 102
  • 1
    Code samples have been added. I don't think this question is duplicated with the provided one. `null !` is not used when dereferencing a member here. – Yishu Fang Apr 27 '17 at 05:18
  • 2
    The answer to that question explains it, it applies to any expression, not only dereferencing a member: "this expression cannot be null or undefined here". So the real question is, how null can not be null? The answer: it can't, it's just that something is declared as non-nullable, but it's necessary to assign null to it in appropriate circumstances (in second example - in the `dispose()` function, to avoid holding on a reference to some memory for example), so non-null assertion operator is used to suppress compiler errors. – artem Apr 27 '17 at 05:31

0 Answers0