0

I tried various websites, I tried even reddit link1, Everywhere I am finding that expressions return a value and statements return undeifned.But I want to know reason for "why expressions return value and why statements return undefined"

1+1
2(why?)
let x = 1+1;
undefined(why?)
  • Not **all** statements return `undefined`. Variable declarations do, though. An assignment statement doesn't (it returns the value assigned), try `let x;` (which will show you `undefined`) and then `x = 42;` which will show you `42`. Similarly, the result of a block statement is the last value produced within the block: `{ let x; x = 42; }` results in `42`. – T.J. Crowder Feb 13 '22 at 12:35

0 Answers0