Front end developer specialising in JavaScript and React. Experienced in all aspects of modern front end development. Passionate about making accessible, secure and performant software.
Hmm, thanks for raising that point. To make sure I'm understanding it: Do you mean that, after you define a variable as a string, you can never assign it to null? So you don't need a null check in that case? And that maybe I should mention that in the article?
If so, then that's a good point. I might modify the article a bit and add that example. TypeScript also has the same feature.
In the above code, the compiler will fail if you if you try to use canBeNull without applying null checks first. In the second case, it won't because... well, it cannot be null.
Note that I explicitly set the type on the second variable though it's not necessary for better readability.
Front end developer specialising in JavaScript and React. Experienced in all aspects of modern front end development. Passionate about making accessible, secure and performant software.
You might be aware that Kotlin offers two data-types for each "regular" data type: one nullable and one not nullable.
While you mention the former ("Use a type system that forces null checks") I don't seem to find the latter.
Otherwise, good post.
Hmm, thanks for raising that point. To make sure I'm understanding it: Do you mean that, after you define a variable as a string, you can never assign it to null? So you don't need a null check in that case? And that maybe I should mention that in the article?
If so, then that's a good point. I might modify the article a bit and add that example. TypeScript also has the same feature.
Thank you.
In the above code, the compiler will fail if you if you try to use
canBeNull
without applyingnull
checks first. In the second case, it won't because... well, it cannot benull
.Note that I explicitly set the type on the second variable though it's not necessary for better readability.
Thanks for the clarification. I modified that section to mention non-nullable types and credited you for pointing them out.
Please let me know if you don't want the credit or if you'd rather be credited in a different way.
I didn't expect credit so that's very fine, thanks!