Short Circuiting With && and || (JavaScript)

preview_player
Показать описание
Hi, I'm Wesley. I'm a brand ambassador for Kinde (paid sponsorship).

👉 Discord: all my courses have a private Discord where I actively participate

⏱️ Timestamps:
0:00 - Solution

#webdevelopment #coding #programming
Рекомендации по теме
Комментарии
Автор

Easy and straight to the point.
Here's my insights I got from the video:
&& --> both conditions must be true in order to run the second part. If one is false, the condition is immediately false and will not even take into consideration, the second part. Both conditions must be true
|| --> if the first condition is true, immediately stop. if the first condition is false, then run the other condition.

pluderr
Автор

I have been testing and here's what I noticed : if you said console.log(9) && 1, you would still receive a log to your console because even though you evaluated the whole expression to "false" (console.log returns undefined), it still ends up logging your input as an indirect operation. So, the actual logging of the input still happens independently of whether it is evaluated as "true" or "false". Finally, it shortcircuits to the first false operand/evaluates its value, and if all operands happen to be true, it always takes the value of the last operand. Is this a correct understanding? Thanks

andromilk
Автор

So it's just a simplified if statement. Is that the point? Instead of writing an if statement you could just && or ||

rt-uhmt