Javatpoint Logo
Javatpoint Logo

JavaScript Logical Assignment Operators

Javascript logical assignment operators help to use the logical operators with the default and another expression. It works between two expressions or values with a single operator. ES2021 provides three logical assignment operators, which are as follows:

  • Logical AND assignment operator
  • Logical OR assignment operator
  • Nullish coalescing assignment operator

The following table displays the difference between the basic and logical assignment operators.

ES Logical Assignment Operators Basic Logical Operators
a &&= b a && (a = b)
a ||= b a || (a = b)
a ??= b a ?? (a = b);

Logical AND assignment operator (&&=)

The &&= symbol is a "Logical AND assignment operator" and connects two variables. If the initial value is correct, the second value is used. It is graded from left to right.

Syntax

The following syntax shows the Logical AND assignment operator with the two values.

Examples

The examples work with multiple values using the "Logical AND assignment operator" in the javascript.

Example1:

The following example shows basic values for the "AND assignment operator" in javascript.

Output

The image shows the "logical AND assignment operator's data" as an output.

JavaScript Logical Assignment Operators

Example2:

The following example shows the "AND assignment operator" hash in javascript.

Output

The image shows the "logical and assignment operator's data" as an output.

JavaScript Logical Assignment Operators

Example3:

The following example shows an array for the "AND assignment operator" in javascript.

Output

The image shows the "logical and assignment operator's data" as an output.

JavaScript Logical Assignment Operators

Logical OR assignment operator (||=)

The ||= is a "logical OR assignment operator" between two values. If the initial value is incorrect, the second value is used. It is graded from left to right.

Syntax

The following syntax shows the Logical OR assignment operator with the two values.

Examples

The examples work with multiple values using the " Logical OR assignment operator" in the javascript.

Example1:

The following example shows basic values for the "Logical OR assignment" in javascript. Here, We can use simple numeric values.

Output

The image shows the "logical OR assignment operator's data" as an output.

JavaScript Logical Assignment Operators

Example2:

The following example shows the "OR assignment operator" hash in javascript.

Output

The image shows the " Logical OR assignment operator's data" as an output.

JavaScript Logical Assignment Operators

Example3:

The following example shows arrays for the "OR assignment operator" in javascript.

Output

The image shows the " Logical OR assignment operator's data" as an output.

JavaScript Logical Assignment Operators

Nullish coalescing assignment operator (??=)

The ??= is a "Nullish coalescing assignment operator" between two values. The second value is assigned if the first value is undefined or null. It is graded from left to right.

Syntax

The following syntax shows the Logical nullish assignment operator with the two values.

Examples

The examples work with multiple values using the " Logical nullish assignment operator" in the javascript.

Example1:

The following example shows basic values for the "Logical nullish assignment" in javascript. Here, We can use simple numeric values.

Output

The image shows the "logical nullish assignment operator's data" as an output.

JavaScript Logical Assignment Operators

Example2:

The following example shows hash values for the "Logical nullish assignment" in javascript.

Output

The image shows the "logical nullish assignment operator's data" as an output.

JavaScript Logical Assignment Operators

Example3:

The following example shows array values for the "Logical nullish assignment" in javascript. The nullish operator uses the null and the "jtp" value to show functionality.

Output

The image shows the "logical nullish assignment operator's data" as an output.

JavaScript Logical Assignment Operators

Conclusion

The javascript logical assignment operators help to operate logical conditions between two inputs in all data formats. The "and", "or", and nullish logical operation works by these operators in the javascript language.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA