//if a first value is a truthy value then it will immediately return the first value without evaluate the second value console.log(3 || "Debasish");//3 console.log('' || "Debasish");//Debasish console.log(true || 0);//true console.log(undefined || null);//null
console.log(undefined || 0 || '' || "Hello" || 23 || null); //Hello // Here hello is the first truthy value in the chain and it Short circuiting the entire chain and return Hello //Helps setting up the default value
When it comes to short-circuiting && works the exact opposite of ||.Returns falsy values immediately.
console.log(0 && "Debasish");//0 console.log(7 && "Debasish");//Debasish console.log("Hello" && 23 && null && "debasish"); //null
I hope you find it useful, let me know your thoughts on this in the comments. If you have any issues or questions about it, feel free to contact me. Thank you 🌟 for reading! like, share and subscribe to my newsletter for more! 💖