DEV Community

Cover image for Assignment has a return value in JS
icncsx
icncsx

Posted on

Assignment has a return value in JS

console.log(b=1) // 1
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Top comments (2)

Collapse
 
noels_john profile image
John Noels

If you're struggling with a challenging Do My ASSIGNMENT or need help with a marketing assignment, getting expert support can make all the difference. A reliable writing service can guide you through structuring, research, and editing, helping you save time while enhancing your work. Anyone have experiences with good services?

Collapse
 
arpple profile image
Arpple

I think it's for REPL, so it will show the final result for assignment as well

> a = 1 + 2
3
Enter fullscreen mode Exit fullscreen mode