I need help with undefined and i do not know what to do

Let’s try this.

  1. This is declaring a variable.

var variableName;

Right now it’s value is undefined, you can think of it as empty for now.

  1. This is initializing*, or assigning to, the above declared variable a value.

variableName = "someStringValue";

  1. This is declaring and initializing/assigning the variable in one line.

var variableName = "someStringValue";

Not sure if this will help
https://www.khanacademy.org/computing/computer-programming/programming/variables/pt/intro-to-variables


  • On a side note, and i realize this is probably not at all the right place for this comment, but anyway.

I would like some clarification on this myself. So anyone, please correct me if I am wrong. I actually believe using the word initialize is incorrect, it should be assign not initialize. To my understanding, initialization refers to the memory allocation stage. When the code runs declared variables are initialized in memory and implicitly assigned the value undefined.

6.1.1The Undefined Type#
The Undefined type has exactly one value, called undefined. Any variable that has not been assigned a value has the value undefined.

This might just be terminological nitpicking, and i know i have seen the word initialize used as meaning assigning plenty of places, by people far smarter than me.
Thoughts, comments?

1 Like