3 ms·
I've never seen `!!!` in JavaScript, and I do a lot of it. Care to share?
by eropple 3y ago
I've never seen `!!!` in JavaScript, and I do a lot of it. Care to share?
- jve 3y agoAnd line breaks after return statement? Is that true? Haven't stumbled on that one. So this is probably misinformation.
- eropple 3y agoNo, that one is true. JS automatic semicolon insertion is dumb. return <p> A JSX paragraph </p> is a common mistake from novices; it'll return void/undefined. In TypeScript, at least, you get yelled at for this.
- littlecranky67 3y agoShouldn't have made an example in the if-statement as it is mostly useless there. But triple ! is very common to negate-and-convert a possibly falsy statement (undefined, null, false/true): const x: boolean | undefined | null = getValue(); const not_x: boolean = !!!y I added TS type annotation for clarity, although could be inferred if `getValue` is typed accordingly.
- eropple 3y agoI've seen `!!` and I've seen `!`, but what would `!!!` get you here that the other two don't?
- littlecranky67 3y agonegation plus cast to boolean. See this for more info: https://stackoverflow.com/questions/21154510/the-use-of-the-triple-exclamation-mark https://stackoverflow.com/questions/21154510/the-use-of-the-...