-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Logical Operators #61
Labels
Comments
#64 - Pull Request updated. |
jsartisan
added a commit
that referenced
this issue
May 18, 2024
Co-authored-by: Pawan Kumar <6636360+jsartisan@users.noreply.github.com>
Merged
jsartisan
added a commit
that referenced
this issue
May 18, 2024
Co-authored-by: Pawan Kumar <6636360+jsartisan@users.noreply.github.com>
Merged
jsartisan
added a commit
that referenced
this issue
May 18, 2024
Co-authored-by: Pawan Kumar <6636360+jsartisan@users.noreply.github.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Info
Question
What will the following code snippet log to the console?
Solution
The console output will be:
Explaination
In the code snippet, we are using the logical AND (
&&
) and logical OR (||
) operators to evaluate expressions involving variablesa
,b
, andc
.Logical AND (
&&
) Operation:&&
operator returns the first falsy value it encounters, or the last value if all values are truthy.a && b && c
is evaluated:a
is1
, which is truthy.b
is""
, which is falsy.c
is0
, which is falsy.a && b && c
evaluates to the first falsy value encountered, which is""
.console.log(a && b && c);
logs""
.Logical OR (
||
) Operation:||
operator returns the first truthy value it encounters, or the last value if all values are falsy.a || b || c
is evaluated:a
is1
, which is truthy.b
is""
, which is falsy.c
is0
, which is falsy.a || b || c
evaluates to the first truthy value encountered, which is1
.console.log(a || b || c);
logs1
.The text was updated successfully, but these errors were encountered: