What is the output of a logical OR operation if one of the inputs operands is true?


Getting Image
Please Wait...

Course

NCERT

Class 12Class 11Class 10Class 9Class 8Class 7Class 6

IIT JEE

Exam

JEE MAINSJEE ADVANCEDX BOARDSXII BOARDS

NEET

Neet Previous Year (Year Wise)Physics Previous YearChemistry Previous YearBiology Previous YearNeet All Sample PapersSample Papers BiologySample Papers PhysicsSample Papers Chemistry

Download PDF's

Class 12Class 11Class 10Class 9Class 8Class 7Class 6

Exam CornerOnline ClassQuizAsk Doubt on WhatsappSearch DoubtnutEnglish DictionaryToppers TalkBlogJEE Crash CourseAbout UsCareerDownloadGet AppTechnothlon-2019

Logout

Login

Register now for special offers

+91

Home

>

English

>

Class 12

>

Computer Science

>

Chapter

>

Variables, Expressions

>

What will be the output of a L...

Text Solution

false true true or false None of the above

Solution : true or false

Related Videos

104439613

62

3.6 K

2:57

7 या 11 आने की या प्रायिकता होंगे यदि दो पास फेंके जाते है ?

112170643

100

8.1 K

निम्न में से असत्य कथन है-

112168633

0

7.1 K

यदि घोल में विलेय का संयोजन होता है तो वांटहॉफ गुणांक 1 से कम होगा .

94832670

0

9.5 K

2:07

यदि रेखिक समीकरणों का कोई युग्म सगत है ,तो इसके आलेख की रेखाए होगी :

112168652

1.8 K

9.4 K

2:49

जल की मोललता कितनी होगी ?

58124202

46

4.5 K

1:47

यदि किसी पदार्थ की आपेक्षिक चुम्बकशीलता 0.9999 है तो इसकी प्रकृति होगी -

Show More

Comments

Add a public comment...

Follow Us:

Popular Chapters by Class:

Class 6

AlgebraBasic Geometrical IdeasData HandlingDecimalsFractions

Class 7

Algebraic ExpressionsComparing QuantitiesCongruence of TrianglesData HandlingExponents and Powers

Class 8

Algebraic Expressions and IdentitiesComparing QuantitiesCubes and Cube RootsData HandlingDirect and Inverse Proportions

Class 9

Areas of Parallelograms and TrianglesCirclesCoordinate GeometryHerons FormulaIntroduction to Euclids Geometry

Class 10

Areas Related to CirclesArithmetic ProgressionsCirclesCoordinate GeometryIntroduction to Trigonometry

Class 11

Binomial TheoremComplex Numbers and Quadratic EquationsConic SectionsIntroduction to Three Dimensional GeometryLimits and Derivatives

Class 12

Application of DerivativesApplication of IntegralsContinuity and DifferentiabilityDeterminantsDifferential Equations

Privacy PolicyTerms And Conditions

Disclosure PolicyContact Us

The logical OR (||) operator (logical disjunction) for a set of operands is true if and only if one or more of its operands is true. It is typically used with boolean (logical) values. When it is, it returns a Boolean value. However, the || operator actually returns the value of one of the specified operands, so if this operator is used with non-Boolean values, it will return a non-Boolean value.

Try it

Syntax

Description

If expr1 can be converted to true, returns expr1; else, returns expr2.

If a value can be converted to true, the value is so-called truthy. If a value can be converted to false, the value is so-called falsy.

Examples of expressions that can be converted to false are:

  • null;
  • NaN;
  • 0;
  • empty string ("" or '' or ``);
  • undefined.

Even though the || operator can be used with operands that are not Boolean values, it can still be considered a boolean operator since its return value can always be converted to a boolean primitive. To explicitly convert its return value (or any expression in general) to the corresponding boolean value, use a double NOT operator or the Boolean constructor.

Short-circuit evaluation

The logical OR expression is evaluated left to right, it is tested for possible "short-circuit" evaluation using the following rule:

(some truthy expression) || expr is short-circuit evaluated to the truthy expression.

Short circuit means that the expr part above is not evaluated, hence any side effects of doing so do not take effect (e.g., if expr is a function call, the calling never takes place). This happens because the value of the operator is already determined after the evaluation of the first operand. See example:

function A() { console.log('called A'); return false; } function B() { console.log('called B'); return true; } console.log(B() || A()); // Logs "called B" due to the function call, // then logs true (which is the resulting value of the operator)

Operator precedence

The following expressions might seem equivalent, but they are not, because the && operator is executed before the || operator (see operator precedence).

true || false && false // returns true, because && is executed first (true || false) && false // returns false, because grouping has the highest precedence

Examples

Using OR

The following code shows examples of the || (logical OR) operator.

o1 = true || true // t || t returns true o2 = false || true // f || t returns true o3 = true || false // t || f returns true o4 = false || (3 === 4) // f || f returns false o5 = 'Cat' || 'Dog' // t || t returns "Cat" o6 = false || 'Cat' // f || t returns "Cat" o7 = 'Cat' || false // t || f returns "Cat" o8 = '' || false // f || f returns false o9 = false || '' // f || f returns "" o10 = false || varObject // f || object returns varObject

Note: If you use this operator to provide a default value to some variable, be aware that any falsy value will not be used. If you only need to filter out null or undefined, consider using the nullish coalescing operator.

Conversion rules for booleans

Converting AND to OR

The following operation involving booleans:

bCondition1 && bCondition2

is always equal to:

!(!bCondition1 || !bCondition2)

Converting OR to AND

The following operation involving booleans:

bCondition1 || bCondition2

is always equal to:

!(!bCondition1 && !bCondition2)

Removing nested parentheses

As logical expressions are evaluated left to right, it is always possible to remove parentheses from a complex expression following some rules.

The following composite operation involving booleans:

bCondition1 && (bCondition2 || bCondition3)

is always equal to:

!(!bCondition1 || !bCondition2 && !bCondition3)

Specifications

Specification
ECMAScript Language Specification
# prod-LogicalORExpression

Browser compatibility

BCD tables only load in the browser

See also

What is the output of a logical or in operation if one of the inputs operands is false?

Logical OR operator give true as output if at least one of the operands is true. 13) What is the output of Logical AND (&) operation if one of the inputs/operands is false? Explanation: false & (anything) is false.

What is the output of an or operation if one of the operands or expression is true?

|| (Logical OR) operator If one of the operands or expressions is true, it will return 1. If all of them are false, it will return 0.

What logical operator results true when both operands are true?

The && (logical AND) operator indicates whether both operands are true. If both operands have nonzero values, the result has the value 1 . Otherwise, the result has the value 0 .

What is the output of any logical operation?

The logical AND operation will yield a TRUE only if all the operands are TRUE. Table 26.4 gives the result of the AND (&&) operator for the operation A&& B. The logical OR operation yields a TRUE if any one of the operands is TRUE.

Toplist

Neuester Beitrag

Stichworte