[SOLVED] Two ways of Storing Values with the Assignment Operator?

[SOLVED] Two ways of Storing Values with the Assignment Operator?
0.0 0

#1

Hi so I was doing this challenge where I had to assign the value 7 to variable a and then assign the contents of variable a to variable b.

I did the second option first and was able to passed the test. Then I found out I did it slightly differently from what FCC told me. Was what I did considered correct as well? Or should I scratch that and just do the first option.

Capture


#2
  1. You only use the var keyword when you are first declaring a variable. You don’t use it again for the same variable.
var a = 7;
var b = 7; // this line doesn't do anything meaningful because the contents of b are immediately replaced
b = 7; // this immediately overwrites the value that was previously stored in b

#3

Oh thank you, I accidentally added var on the last row for both of them.

Imagine the var the the end are gone of both of them. Would the bottom option still be correct?


#4

You still want to use var the first time that you create (“declare”) a variable.


#5

Thanks for the help, I got it now.