Logical AND Assignment Operator (&&=)
The logical AND assignment operator (&&=) assigns the right operand to the left operand if the left operand is truthy; otherwise, it retains the left operand value in JavaScript.
Syntax:
x &&= y
is equivalent to
x && (x = y)
Example: This example shows the basic use of the Javascript Logical AND assignment(&&=) operator.
Javascript
let x = 5; let y = 10; // Changing the value using logical // AND assignment operator x &&= y; console.log(x); let name = { firstName: "Ram" , }; console.log(name.firstName); // Changing the value using logical // AND assignment operator name.firstName &&= "Shyam" ; // Here the value changed because // name.firstName is truthy console.log(name.firstName); |
10 Ram Shyam
JS 2020 – ECMAScript 2020
JavaScript ECMAScript 2020 (ES11) introduced new features like optional chaining, nullish coalescing, dynamic import(), BigInt, and Promise.allSettled(), etc. enhancing language capabilities for modern web development needs.
JavaScript 2020 (ES11) or ECMAScript 2020 new features are:
BigInt |
type for arbitrary precision integers beyond the Number’s limit. |
String matchAll() |
returns an iterator for all regex matches in the string. |
The Nullish Coalescing Operator (??) |
returning right operand if the left is nullish, else left. |
The Optional Chaining Operator (?.) |
accessing nested properties if they exist, otherwise returns undefined. |
Logical AND Assignment Operator (&&=) |
assigns the right operand to the left if the left is truthy. |
Logical OR Assignment (||=) |
assigns the right operand if the left is falsy, else left. |
Nullish Coalescing Assignment (??=) |
the operator assigns the right operand if the left is nullish, else left. |
Promise allSettled() |
returning an array of promise results with status and value. |
Dynamic Import |
enables asynchronous import of modules at runtime. |