Does initialized mean if variable is a number and uninitialized if variable isnt a number but a string instead?
No, initialized means a variable was declared (i.e. using var, let, or const) and was assigned a value. The value could be of any type (number, string, object, boolean, etc). If you just use the var, let or const in front, the variable is declared, but not initialized.
For example, the following variable is declared but not initialized:
In the following example, the variable is initialized with a string:
So uninitalized means if variable has no value basicaly? And also undefinited variable is the one without number but with a string instead?
No, an undefined variable is a non-existent variable. It has not even been declared.
Below, I declare a variable, but try to reference a variable that does not exist.
var myDeclaredVariable; console.log(someOtherVariable); // results in ReferenceError: someOtherVariable is not defined
What part is still confusing? I will do my best to help you to understand.
Im still confused about undefined variable, it seems easy but hard to grasp what it would exactly mean. Does it mean for example if var has no name given? Thats one thing im thinking considering the word undefined, since we define variable with some name.
An undefined variable does not exist at all. You have not declared it (or initialized it).
If I use the word var in front of a variable name, then the variable is declared (see below).
var myVariable; // this variable is declared and is "defined"
Even if I do not put the word var in front of a variable name, but I do assign it a value, then I have initialized the variable. See below for example.
anotherVariable = 50;
So let me clarify something I said in the previous reply. In response to one of your questions, I said “No, an undefined variable is a non-existent variable. It has not even been declared.” I should have said a variable which has not been defined (declared or initialized) is a non-existent variable.
I can not reference a variable which has not been defined. So, if the following is my only code:
This above will result the following Reference error:
ReferenceError: myVariable is not defined
If instead I would have had the code below:
var myVariable; console.log(myVariable);
I always viewed the initial value of a variable declaration of
var to be