Re:Microsoft DeviceScript – TypeScript for Tiny IoT Devices
by littlecranky67 on Friday June 09, 2023 @02:19PM
(#36261862)
Good luck understanding things like `if(!!!c) { ... }` or why a line-break after a return statement matters in JavaScript/TypeScipt ;) JS has its own footguns and legacy baggage.
[ Parent
| on HN ]
Re:Microsoft DeviceScript – TypeScript for Tiny IoT Devices
by eropple on Friday June 09, 2023 @04:05PM
(#36263423)
I've never seen `!!!` in JavaScript, and I do a lot of it. Care to share?
Re:Microsoft DeviceScript – TypeScript for Tiny IoT Devices
by jve on Saturday June 10, 2023 @01:55AM
(#36268001)
And line breaks after return statement? Is that true? Haven't stumbled on that one. So this is probably misinformation.
Re:Microsoft DeviceScript – TypeScript for Tiny IoT Devices
by eropple on Saturday June 10, 2023 @09:33AM
(#36270330)
No, 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.
Re:Microsoft DeviceScript – TypeScript for Tiny IoT Devices
by littlecranky67 on Monday June 12, 2023 @05:15AM
(#36290521)
Shouldn'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.
Re:Microsoft DeviceScript – TypeScript for Tiny IoT Devices
by eropple on Monday June 12, 2023 @05:07PM
(#36301142)
I've seen `!!` and I've seen `!`, but what would `!!!` get you here that the other two don't?
Re:Microsoft DeviceScript – TypeScript for Tiny IoT Devices
by littlecranky67 on Tuesday June 13, 2023 @05:23AM
(#36307667)
negation plus cast to boolean. See this for more info: https://stackoverflow.com/questions/21154510/the-use-of-the-...