Nice :)
We can also replace chars that we don't know with either mapped char or with a ?
?
'Wół'.replace(/[^a-zA-Z]/g, c => mapping[c] ?? '?')
Hey Kostia,
currently trying to understand your code. Do you mean || instead of ??.
||
??
Hey, Michael!
Yeah, in this particular case || would work as well as ??. Nullish coalesce would be useful if you have a mapping that simply drops some char, e.g:
mapping
const mapping = { ą: "a", ć: "c", ę: "", // <-- drop ę ł: "l", // etc ... };
Here || wont work. But that's just a case I made up 🙂
Awesome, thanks for that!
I didn't know that JavaScript added a nullish coalescing operator in ES2020! Currently running Node 12, I should probably update it, too!
Yeah, JS is getting hard to track :)
Also note ?. conditional chaining — helps a lot!
?.
And they've added more operators just recently (@ stage 4):
||= &&= ??= for conditional assignment (dunno why...)
||=
&&=
??=
article on recent updates: dev.to/hemanth/stage-4-features-5a26
not mentioning other #, |>, {| }, etc early stage propositions — 🤯
#
|>
{| }
Thanks for the summary!
I already use the ?. in my TypeScript projects, will have a look at the other ones!
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Nice :)
We can also replace chars that we don't know with either mapped char or with a
?
Hey Kostia,
currently trying to understand your code.
Do you mean
||
instead of??
.Hey, Michael!
Yeah, in this particular case
||
would work as well as??
.Nullish coalesce would be useful if you have a
mapping
that simply drops some char, e.g:Here
||
wont work. But that's just a case I made up 🙂Awesome, thanks for that!
I didn't know that JavaScript added a nullish coalescing operator in ES2020!
Currently running Node 12, I should probably update it, too!
Yeah, JS is getting hard to track :)
Also note
?.
conditional chaining — helps a lot!And they've added more operators just recently (@ stage 4):
||=
&&=
??=
for conditional assignment (dunno why...)article on recent updates: dev.to/hemanth/stage-4-features-5a26
not mentioning other
#
,|>
,{| }
, etc early stage propositions — 🤯Thanks for the summary!
I already use the
?.
in my TypeScript projects,will have a look at the other ones!