Basic JavaScript - Assigning the Value of One Variable to Another

Tell us what’s happening:
Random and might seem like a dumb question! But why is this answer wrong:
var b = var a;

I thought I understood that everything to the right of the = operator is performed before the value is assigned… so just got confused there.

Im new new so thanks for any insight!

Your code so far

// Setup
var a;
a = 7;
var b;

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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Assigning the Value of One Variable to Another

Link to the challenge:

Hi Mickcha and welcome to the forum!

If I understand correctly, the reason “var b = var a” is incorrect in this case is because the code is trying to initialize var a, not assign its value to var b.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.