JavaScript Logical AND assignment (&&=) Operator (original) (raw)

Last Updated : 06 Jan, 2023

This operator is represented by x &&= y, and it is called the logical AND assignment operator. It assigns the value of y into x only if x is a truthy value.

We use this operator x &&= y like this. Now break this expression into two parts, x && (x = y). If the value of x is true, then the statement (x = y) executes, and the value of y gets stored into x but if the value of x is a falsy value then the statement (x = y) does not get executed.

Syntax :

x &&= y

is equivalent to

x && (x = y)

Example: This example shows the basic use of the Javascript Logical AND assignment(&&=) operator.

JavaScript `

`

Output :

"Ram" "Shyam" "" ""

Example 2: This example shows the basic use of the Javascript Logical AND assignment(&&=) operator.

HTML `

Geeksforgeeks

Javascript Logical AND assignment(&&=) operator

`

Output :

Javascript Logical AND assignment(&&=) operator

Javascript Logical AND assignment(&&=) operator

We have a complete list of Javascript Operators, to check those please go through the Javascript Operators Complete Reference article.

Supported Browsers: