Basic JavaScript - Assigning the Value of One Variable to Another

Tell us what’s happening:

I am LITERALLY doing exactly what it says. WTF?

Your code so far

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

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36

Challenge Information:

Basic JavaScript - Assigning the Value of One Variable to Another

You should not re-declare variables inside of the same scope ever. Don’t use the var keyword (or the let or const keyword) again after its used once for a variable.

Also, this line is “backwards”. It takes the contents of b and tries to assign it to the variable a. The = operator works from right to left!

1 Like

Hello, you can think of variables like containers that get created when you define them with a keyword like var. Once you create (aka declare) the variable you no longer need the var keyword to access or change the value thats in the variable.

for example:

var num = 2;

console.log(num); // 2
// I can change this without var since it is already declared
num = 6;
console.log(num); // 6

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