Yeah... I think I cropped it to the wrong error. It should have read: This condition will always return true since the function is always defined. Did you mean to call it instead?
example for Nullish Coalescing doesn't really seem to explain why it's useful: "old way" would just be var calculator = someCalculator || new Calculator();
I was also wondering what's the difference between those two and I've found it. Nullish Coalescing better handles cases when it comes to truthy/falsy values.
For example:
const a = 0
const b = a || 100
console.log(b) // 100
Same thing, but different result with Nullish Coalescing:
const a = 0
const b = a ?? 100
console.log(b) // 0
I personally hate the use of the || operator in this context, but that's mostly because my background is a C# one where I read the operator and think that b would be assigned to true since a and 100 would both be evaluated as booleans.
Obviously they wouldn't, but to me ?? is way more intuitive than the use of || in this context.
I am Software Developer, currently interested in static type languages (TypeScript, Elm, ReScript) mostly in the frontend land, but working actively in Python also. I am available for mentoring.
I think some of the examples are not in the right order. Nice otherwise :)
As in you'd like to see the functions reordered within the gists for readability?
Ya kind of
Does "Uncalled function check" has wrong screenshot? Because the screenshot show "declare" error instead of uncalled function check
Yeah... I think I cropped it to the wrong error. It should have read:
This condition will always return true since the function is always defined. Did you mean to call it instead?I've made the edit.
I feel shame. Don't publish tired.
Yessss I've been waiting for Optional Chaining and Nullish Coalescing so hard, thanks for writing this up and appearing on my newsfeed 🙌
I know. Almost every merge request I review in the JavaScript / TypeScript world I wish the committer had access to optional chaining.
example for Nullish Coalescing doesn't really seem to explain why it's useful: "old way" would just be
var calculator = someCalculator || new Calculator();I was also wondering what's the difference between those two and I've found it. Nullish Coalescing better handles cases when it comes to truthy/falsy values.
For example:
Same thing, but different result with Nullish Coalescing:
I personally hate the use of the
||operator in this context, but that's mostly because my background is a C# one where I read the operator and think thatbwould be assigned totruesinceaand100would both be evaluated as booleans.Obviously they wouldn't, but to me
??is way more intuitive than the use of||in this context.I thought I remembered something like this being the edge case where this was useful... Thank you, this seems like a better example!
Some more details about why optional chaining is not so perfect thing
dev.to/macsikora/what-is-wrong-wit...
The decalre keyword is not really a feature, but compatebility option with es class members
devblogs.microsoft.com/typescript/...