Understanding Uninitialized Variables help please

Tell us what’s happening:

Your code so far

// Initialize these three variables
var a;
5= a;
a= 5;
var b;
b= 10;
var c;
c= I am a;

// Do not change code below this line

a = a + 1;
b = b + 5;
c = c + " String!";

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:65.0) Gecko/20100101 Firefox/65.0.

Link to the challenge:

Oh my…
Alright. So, when you declare a variable with var or let, you are not required to assign it an initial (get it? initial–initialized?) value:

var a;
let b;

But this can be dangerous. Well, not super dangerous in JavaScript since they default to undefined, but in some other languages they could be some random value.

Usually, it is good practice to, when you are declaring a variable, give it an initial value, or initialize it. You assign a value to a variable with a single equals sign: = and the variable always goes on the left and the value going into said variable always goes on the right:

let foo = "bar";

assigns the string “bar” to the variable name foo.

Does that answer your question?

i dont understand pls can you help me solve the code , thanks

Okay, so the problem declares three variables, right?

var a;
var b;
var c;

based on the instructions and what I wrote above, what value do these three variables contain?

You declare a variable with var a, when you initialise a variable you assign a value to it on the same line you declare it
var a = 'something'

You have to initialise the variables following the indications in the challenge text

1 Like

var a= 5;
var b= 10;
var c= I am a;

The way I do:
check what the task ask you:
a should be defined and evaluated to have the value of 6
and we have instructions:
// Do not change code below this line
a = a + 1;
so quick math
a=6; a= 5+1;
so at the beginning we should have a=5; var value can change down the line
you need to add variable values, because at the moment they are empty

// Initialize these three variables

var a = 5;

var b = 10;

var c = “I am a”;

Almost there. just when you have something that you want to be in plain human language, we put it in quotes: so var c = "i am a";

You might want to go back to the start again and re-read the assignments, don’t rush it.

5 = a;

The left-hand side of the assignment operator is the receiver, you are trying to assign a variable to a primitive data type. You can not assign a value to 5, it is what it is, the number 5 and nothing else.

c = I am a;

The text on the right-hand side here is supposed to be a string, you use quotes "" or '' around text to make it a string “I am a”

This is declaring variables

var a;
var b;
var c;

This is initializing the variables

a = "some string";
b = 42;
c = b;

This is declaring and initializing the variables in one line.

var a = "some string";
var b = 42;
var c = b;
1 Like

i just initialized and it worked, i had to declare before, thanks so much