Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
Alright now
let's take a look at the logical operators. We use these operators
to make decisions based on multiple conditions.
In JavaScript we have three types of logical operators,
logical and logical or and logical not. Let's see
each of these operators in action. So I'm going to start
with the logical and which indicated by
2 ampersands. So here's the basic rule of thumb.
This logical and returns true if both
operands are TRUE. What do I mean by that?
Well, let's do a console.log,
true and true. So we have two operands,
they are both true, so the result of evaluating,
this expression will be true. Let's have a look on the console.
Look, here we get true. Now if either
of these is false, the result will be false, so I'm going to change
this to false, save the changes,
note that we get false on the console, it doesn't matter which one is
false, if I make the other one false, or both of them false, I
still get false. So logical and returns
true if both operands are true. Now you might be asking
what is a real world use case for this operator? Well, let's
imagine we want to build an application for approving loans.
So we want to see if the applicant has high income and
a good credit score, then they will be eligible for loans.
So, I'm going to delete all this,
and declare a couple variables, high income, we're going to
set that to true, and good credit
Score, we're going to send that to true as well.
So here we're dealing with two conditions, we want to make sure that
the applicant has high income, and good credit score.
That's where we use the logical and. So we can declare another
variable, eligibleForLoan
and this is where we use the logical and operator.
So high income and goodCreditScore.
Now, if we log this on the console,
eligible for loan, we should get true, and
here's the result, now let's take a look at the logical or.
So, logical or is indicated by
two vertical lines, and this returns true
if one of the operands
is True. It doesn't matter which one, whether the one on the left,
or the one on the right or both of them, as long as we have one true
operand, the result of this expression will be true. So here's
an example. I'm going to replace this logical and with
logical or, now in this case both operands are true, so the
result of this expression will also be true. Let's have a look. So I'm going to
save the changes to get true, now if I save one of these to
false, we still get true.
It doesn't matter which one is true. As long as we have one operand
in this expression that evalues to true the
result of this expression will also be true. So this is how we use
the logical or. And finally, let's look at
the not operator. That is indicated by
an exclamation mark. So let's imagine that the
applicant is not eligible for loan, you want to consider the
application as refused. So we can declare
another variable applicationRefused
here we use the not operator, we apply
it on eligibleForLoan, so this is
what happens here. If eligible for loan is true, this
not operator will convert that to false. So whatever
we give it, it will give us the opposite, in this case
eligible for loan is true, this will convert that to false,
and applicationRefused will be false. Because if
someone is eligible for a loan, we don't want to refuse their application, right?
So application refused, is always the opposite of
eligibleForLoan, and that's where we used the not operator.
So let's see this in action. I'm going to change both these conditions
to false. So we're dealing with someone who
has low income and a bad credit score, obviously they are not eligible for
a loan, so let's log this on the console,
eligible for loan, and we can also add a label so
I'm going to add a string, eligible, and here we add
comma, then we apply the not operator,
to set the application refused variable, let's do another console
.log, application refused,
and here we log application refused variable.
Now let's see what we get on the console to save the changes
you can see if this applicant is not eligible
because eligible is false, and application refused is
true because it's always the opposite of eligible for loan.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.