✅ – 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;
S
ScriptyChris528d 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
S
Script528d ago
truly the learning dont stop. haha thanks Chris
UU
Unknown User527d ago