Hello everyone๐
In this article, I will try to explain the behavior of the boolean data type of JavaScript.
We often use if statements in JavaScr...
For further actions, you may consider blocking this person and/or reporting abuse
My background is in more strictly-typed languages like C++ and C#, and the whole "truthy vs falsy" concept still throws me off whenever I write JavaScript. The
!!
syntax in particular makes me gag every time I see it! I know what it's doing, it just looks so odd compared to the other languages I've worked with. Maybe I just need more JavaScript experience...Anyway, thanks for sharing!
Yeah. You will get used to it.
"...but it is always better to handle pure boolean values."
Totally disagree, it just demonstrates a lack of understanding of the JavaScript language and makes code more verbose than is necessary
If you are working on a JavaScript stack on both client and server side then it's fine but with different tech stack, sometimes you may encounter some unexpected bugs.
Agreed, but this article is specifically about JS
Yeah. I myself don't use that syntax often.
I disagree with this.
The falsy values are just:
The
document.all
is an exception and I won't even use this in a codebase. If you try thetypeof
operator returns an "undefined", that's the reason no the function itself. Also, this is used by older browsers and is equivalent todocument.getElementById
.In addition, "always better to handle pure boolean values." shows the lack of understanding about JS.
falsy
objects are helpful and the ability to coerce types makes it easier to work with them, with and without TS.These are also falsy:
The last is an object, which is falsy, in HTML JavaScript.
Hey, thank you for pointing that out. I have added these two.
How did you created this paragraph list of 4 items in the beginning of the post?
It's called a series.
My pleasure!
You know, the title was kind of misleading. True is always true in JavaScript, right?
Actually, it's kind of confusing but good to grab attention ๐.
Happy to know that you got to learn something new. ๐