I’m asking this, because when I try to debug code by using safari console, I found
my_string = ‘abc’
"abc"
it return the the string itself in the console right away
but with var
var my_string = ‘abc’
undefined
Does this mean with var, the expression of variable assignment do not execute or evaluate right away?
No.
What the console does is, it echoes the result of the operation you entered.
The result of a normal assignment
is
abc. The assignment operator returns the value that it assigned.The
varkeyword is a special kind of assignment. It doesn’t return the assigned value (for whichever internal reason), so it’s not echoed by the console.The assignment still takes place immediately in both cases.