708
the hardest exam question
(lemmy.ml)
Post funny things about programming here! (Or just rant about your favourite programming language.)
Falsy zero? What's wrong with that, 1 is true and 0 is false. I thought that was standard logic?
in javascript a property is truthy if it exists
It works with everything except of course for falsy values
So you've got to be extra careful with that logic when you're dealing with numbers.
I am not saying it's wrong though. I'm saying it's often annoying.
ah ok , I think I write this a bit more verbose when using other languages, instead of
I do
so checking for numbers being truthy & existing didn't seem like an issue
In the case of a non-existing property, the value would be undefined rather than null.
And while == and != exist in JavaScript, most linters will throw an error and require a === and !== instead as they should be avoided.
Besides, null is a perfectly valid value for a property, just as 0. Working with API Platform, I couldn't tell the number of times I used this kind of statement:
Probably just as much as