Script
Script3y ago

✅ – Script – 21-22 Nov 7

How do I check if boolean object key contains value? Category is a string, so I just check if it contains any value and then I am able to update it
gig.category = req.body.category ? req.body.category : gig.category;
gig.category = req.body.category ? req.body.category : gig.category;
but approvedForMenu is a boolean. So my ternary operator is checking for true or false instead. I can change the value to true but I cant change it back to false. How do I write the code so I can be able to change it back to false?
gig.approvedForMenu = req.body.approvedForMenu ? req.body.approvedForMenu : gig.approvedForMenu;
gig.approvedForMenu = req.body.approvedForMenu ? req.body.approvedForMenu : gig.approvedForMenu;
4 Replies
ScriptyChris
ScriptyChris3y ago
You can use ??, which checks for null/undefined instead of truthiness/falsiness @Script https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing
Script
ScriptOP3y ago
truly the learning dont stop. haha thanks Chris
reactibot
reactibot3y ago
This question has an answer! Thank you for helping 😄 If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1039288869780197446
reactibot
reactibot3y ago
This thread hasn’t had any activity in 12 hours, so it’s now locked. Threads are closed automatically after 12 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1039288869780197446 Question not getting answered? Maybe it's hard to answer, or maybe you asked at a slow time. Check out these resources for help asking a good question: https://stackoverflow.com/help/how-to-ask http://wp.me/p2oIwo-26