Assignment has a return value in JS

console.log(b=1) // 1

Because assignment has a return value, we are able to chain assignments.

let a;
let b;

a = b = 1

console.log(a); // 1
console.log(b); // 1

Hard to read, but it works…

let a = 1;
let b = 2;

let c = 3 – (a = …


This content originally appeared on DEV Community and was authored by icncsx

console.log(b=1) // 1

Because assignment has a return value, we are able to chain assignments.

let a;
let b;

a = b = 1

console.log(a); // 1
console.log(b); // 1

Hard to read, but it works...

let a = 1;
let b = 2;

let c = 3 - (a = b + 1);

console.log(a); // 3
console.log(c); // 0


This content originally appeared on DEV Community and was authored by icncsx


Print Share Comment Cite Upload Translate Updates
APA

icncsx | Sciencx (2021-11-24T20:47:33+00:00) Assignment has a return value in JS. Retrieved from https://www.scien.cx/2021/11/24/assignment-has-a-return-value-in-js/

MLA
" » Assignment has a return value in JS." icncsx | Sciencx - Wednesday November 24, 2021, https://www.scien.cx/2021/11/24/assignment-has-a-return-value-in-js/
HARVARD
icncsx | Sciencx Wednesday November 24, 2021 » Assignment has a return value in JS., viewed ,<https://www.scien.cx/2021/11/24/assignment-has-a-return-value-in-js/>
VANCOUVER
icncsx | Sciencx - » Assignment has a return value in JS. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/11/24/assignment-has-a-return-value-in-js/
CHICAGO
" » Assignment has a return value in JS." icncsx | Sciencx - Accessed . https://www.scien.cx/2021/11/24/assignment-has-a-return-value-in-js/
IEEE
" » Assignment has a return value in JS." icncsx | Sciencx [Online]. Available: https://www.scien.cx/2021/11/24/assignment-has-a-return-value-in-js/. [Accessed: ]
rf:citation
» Assignment has a return value in JS | icncsx | Sciencx | https://www.scien.cx/2021/11/24/assignment-has-a-return-value-in-js/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.