This post was originally published at kais.blog.
Let's move your learning forward together! Follow me on Twitter for your daily dose of developer ...
For further actions, you may consider blocking this person and/or reporting abuse
Sometimes it is easier to use a boolean flag as a function argument, if splitting the function would result in two almost identical functions. But rather than pass in a boolean, I like to give a unioned string option in TypeScript which is descriptive of what the flag means:
Yeah, nothing is set in stone. If you feel like this is appropriate, go for it. In my opinion it's much better than a boolen flag already. If you are using TypeScript this is a good alternative. However, for JavaScript I won't recommend this, as you could do the following:
At first glance it's not obvious that
"fast"
is an invalid argument here.Thank you for sharing this knowledge. While I was reading I recognized a couple of mistakes/bad practices I've been seeing in the work I'm collaborating on these days... I'll make sure to try and correct them from now on!
Thanks!
An easier fix here:
and that's not even a "new" language feature. And to answer the question: 12. It's 12 zeroes. You can literally read it as a number.
Thanks for your feedback. I really appreciate it. I'd like to add some thoughts to this, though:
First, one billion is 9 zeros in American and British English nowadays (short scale definition). This is sometimes confusing as it's 12 zeros in some other countries (long scale definition). For example, in Germany, we have Million (6 zeros), Milliarde (9 zeros) and Billion (12 zeros). As we have an english-speaking audience here, I've chosen to ignore my country's default definition and used 9 zeros. Also, you usually use English for code.
Second, you are right, you could use the
e
-notation. In this case, it would've been:However, it's important to note that you are just adding zeros here. It's not so useful for other numbers.
Third, I feel like the numeric separator is still a very useful thing. As I said, the
e
-notation can be used, if you have to add zeros. Then, maybe it's easier. Nevertheless, the numeric separator has other uses as well:So, it might not be the right thing to use everytime. Yet, I'd like to highlight that nothing is set in stone and there are always exceptions and different opinions on how to structure and write clean code.
I totally agree that
_
has its uses and can make code much more reasonable in cases wheree
-notation wouldn't do so. But for the specific case of having lots of0
s, I'd always prefer thee
-notation, because you can just read the number of zeroes. Something like1e32
would be difficult to count even with_
-notation.true
. I agree. Maybe next time, I should choose a different example. Thanks for your input, though.Not a big deal and not important for the purpose of the article, just you can't use optional-chaining in a root developer.mozilla.org/en-US/docs/W...
Thanks for mentioning this. I've just tried to come up with a code example fast and have overlooked that in the process. I'll fix it in the article.
thank you for sharing this its very useful content
Thanks. I'm glad I could help.