In the Mac (OS X 10.13.3) terminal, when I enter the REPL for node (v8.10.0) and enter the following various lines I get the indicated outputs:
> let a = 'abc'
undefined
> const b = 'abc'
undefined
> var c = 'abc'
undefined
> d = 'abc'
'abc'
Why the difference in output between the first three versus the last one?
I understand that, in ES5 non-strict mode, var x = 1
and x = 1
result in different variable scopes, but I suspect that's not the issue here.
I also understand that d = 'abc'
is no longer a best practice for JavaScript and is not even allowed in, say, ES5 strict mode. However, I'm just trying to understand either the syntactic differences between the lines and/or how the node REPL interprets input. Does this have something to do with statements versus expressions (or definitions or assignments or declarations or...)?
(I've tried to search StackOverflow, but haven't found the answer in questions entitled 'node.js displays “undefined” on the console' or 'node.js REPL “undefined”
'. I also can't find an answer in the Node.js v8.10.0 Documentation section for REPL. Searching Google for, say, node repl "return value"
, etc. also does not help.)