Why does the regular assignment statement (say, x = 5) return the value assigned (5 in this case), while the assignment combined with a variable d
x = 5
5
When you write var x = 5; it declares x and initalizes its value to 5.
var x = 5;
x
This is a VariableStatement, it returns nothing,
VariableStatement
but x=5 is an expression that assigns 5 to x. as there is no x, JavaScript implicitly creates a global x in normal code
x=5
expression