this post was submitted on 27 Jul 2023
1286 points (99.9% liked)
Technology
59605 readers
3156 users here now
This is a most excellent place for technology news and articles.
Our Rules
- Follow the lemmy.world rules.
- Only tech related content.
- Be excellent to each another!
- Mod approved content bots can post up to 10 articles per day.
- Threads asking for personal tech support may be deleted.
- Politics threads may be removed.
- No memes allowed as posts, OK to post as comments.
- Only approved bots from the list below, to ask if your bot can be added please contact us.
- Check for duplicates before posting, duplicates may be removed
Approved Bots
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
yes, that is a solid logic, one that I also applied and expected to be the result.
that is until a Vue component started complaining that I am passing in a number for a prop that expects a boolean.
turns out the result of that code is actually: 0, because javascript
of course if you flip it and try
then you get false, because that's what you really want in a language, where && behaves differently depending on what is on what side.
I was incorrect; the first part of my answer was my initial guess, in which I thought a boolean was returned; this is not explicitly the case. I checked and found what you were saying in the second part of my answer.
You could use strict equality operators in a conditional to verify types before the main condition, or use Typescript if that's your thing. Types are cool and great and important for a lot of scenarios (used them both in Java and Python), but I rarely run into issues with the script-level stuff I make in JavaScript.