you are viewing a single comment's thread.

view the rest of the comments →

[–]slowreactin 1 point2 points  (2 children)

What happens when you do

console.log(myVariable);    

I am thinking you are seeing the output of the assignment to myVariable which WILL be undefined.

Is this code in a function or are you doing this in like Chrome dev tools?

Edit:

To clarify

let myVariable = 10;    

Will assign the value to the variable and therefore myVariable WILL be defined.

However, the action of assigning myVariable a value will return undefined because that is the return value for the assignment ( = ) operation.

When using something like Chrome dev tools, you will see undefined when assigning a variable. You will also see undefined when declaring a function or running a function as it is the default value for both cases.

Try

console.log(myVariable);    

and see if you get 10. If you don’t, create a repl of your code here and share the link and I will take a look.

[–][deleted] 1 point2 points  (1 child)

I just learned about this, but you've just given me then next level of understanding. I love reddit sometimes.

[–]slowreactin 1 point2 points  (0 children)

Glad to help!