Confusing behaviour with basic type boolean in TypeScript

后端 未结 2 1273
感动是毒
感动是毒 2021-01-25 16:31

From TypeScript webpage: \"The most basic datatype is the simple true/false value, which JavaScript and TypeScript call a boolean value.\"

Ok so far so good, it\'s just

2条回答
  •  深忆病人
    2021-01-25 17:33

    you do not need to compare true/false values with ==/=== because they are already boolean values themselves. thus making it redundant.

    so just do if (a) or if (!a)

    typescript just wants to optimize your code this way. in vanilla JS it is perfectly fine to do if (a === true)

提交回复
热议问题