First Challenge in Basic JavaScript

Tell us what’s happening:

I solved this! it should be
var a;
var a = 7;
var b = a
just a not var a

I don’t know what I am doing wrong!

Your code so far


// Setup
var a;
var b = 2;

// Only change code below this line
var a;
var a = 7; 
var b = var a;

**Your browser information:**

User Agent is: <code>Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36</code>.

**Link to the challenge:**
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/storing-values-with-the-assignment-operator/

When assigning a variable to another variable there is no really need to insert
"var".

You could do either var a; and then a = 2; for example or directly var a = 2;

So it’s up to you.

You don’t have to specify it’s a variable (with var, let or const) multiple times.

1 Like
//declaration a = undefined, since you dont declared a value for the variable
var a;
//declaration b = 2; (it create the variable and assigned 2 to it in the same line of code
var b = 2;
//declares the same variable a so it destroy the old and create a new one a = undefined
var a;
// now create a new variable a and it equals to 7
var a = 7; 
//now create a new b variable that replace the old one and assign to it var a, 
//since var a make a new a variable whit valor undefined then b = undefined
var b = var a;

everytime you declare a variable like var x; javascript give it the value undefined