Here is the code I put into node.js:
let x = 4;
console.log(x);
x = 5;
I got this in the console:
4
5
Any idea why re-assigning a value to x is causing another call to console.log()? I'm in a class involving JS and the instructor isn't quite sure either
Both in the browser console and in the Node repl, after typing in a statement and pressing enter, the "completion value" of the statement you typed in will be printed. With expressions, usually, this is equivalent to what the expression evaluates to. And, in JavaScript, assignments are (unfortunately) expressions - so x = 5 evaluates to 5:
console.log(x = 5);
So when you type the line
x = 5;
and press enter, that completion value - 5 - gets printed.
This behavior does not occur when running files (like node myscript.js, or <script src="myscript.js">) - it's purely a console quirk. If it confuses you, consider only using the console for only playing around with very short toy snippets - for real code, put it into a file, then execute the file.