• Что бы вступить в ряды "Принятый кодер" Вам нужно:
    Написать 10 полезных сообщений или тем и Получить 10 симпатий.
    Для того кто не хочет терять время,может пожертвовать средства для поддержки сервеса, и вступить в ряды VIP на месяц, дополнительная информация в лс.

  • Пользаватели которые будут спамить, уходят в бан без предупреждения. Спам сообщения определяется администрацией и модератором.

  • Гость, Что бы Вы хотели увидеть на нашем Форуме? Изложить свои идеи и пожелания по улучшению форума Вы можете поделиться с нами здесь. ----> Перейдите сюда
  • Все пользователи не прошедшие проверку электронной почты будут заблокированы. Все вопросы с разблокировкой обращайтесь по адресу электронной почте : info@guardianelinks.com . Не пришло сообщение о проверке или о сбросе также сообщите нам.

✨ Understanding `AND (&&)` and `OR (||)` Operators in JavaScript

Lomanu4 Оффлайн

Lomanu4

Команда форума
Администратор
Регистрация
1 Мар 2015
Сообщения
1,481
Баллы
155
Hello friends ?

In this blog, I will explain two simple and powerful tools in JavaScript: the AND (&&) and OR (||) operators. These are called logical operators and are used to check conditions.
Let’s understand them with examples that relate to real life ?‍♂??

? What is AND (&&)?


The && operator checks if both conditions are true ✅✅

If both are true → result is true

If any one is false → result is false ❌

? Real-Life Example:


Let’s say you want to go for a walk ?‍♀

You will go only if:

➡ It is not raining ☀

AND

➡ You have free time ?


let isNotRaining = true;
let hasFreeTime = true;

if (isNotRaining && hasFreeTime) {
console.log("You can go for a walk! ?‍♂");
} else {
console.log("Stay at home! ?");
}

? If both conditions are true, the walk will happen

? If even one is false, no walk today!

? What is OR (||)?


The || operator checks if at least one condition is true ✅

If one is true → result is true

If both are false → result is false ❌❌

? Real-Life Example:


You will order food ? if:

➡ You are hungry ?

OR

➡ There is no food at home ?


let isHungry = false;
let noFoodAtHome = true;

if (isHungry || noFoodAtHome) {
console.log("Order food online! ?");
} else {
console.log("No need to order food. Eat at home! ?️");
}

? Only one condition needs to be true to order food

? Easy to Remember


➡ && → Both conditions must be true ✅ AND ✅

➡ || → Only one condition needs to be true ✅ OR ❌

? Quick Real Example


let hasLaptop = true;
let hasInternet = false;

// Check if you can work from home
if (hasLaptop && hasInternet) {
console.log("You can work from home ??");
} else {
console.log("You can't work from home ?");
}

// Check if you can still do something useful
if (hasLaptop || hasInternet) {
console.log("You can still be productive! ?");
}
✅ Summary Table

OperatorResult is true if...
ANDBoth conditions are true ✅✅
ORAt least one condition is true ✅ or ✅

I hope this blog helps you understand AND and OR operators in a fun and easy way! ?

These are very helpful when writing conditions in JavaScript.

Thanks for reading! ??

~ Himanay Khajuria


Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

 
Вверх Снизу