Challenge 9 Differences between var and let keyword

In Challenge 9 of the JavaScript Certification:

var camper = "James";
var camper = "David";

is the third line the var declaration?

the first and second lines are var declarations, the second variable will overwrite first one without any error, if you replace var with let then js engine will complain that the camper is already declared

what is the third line written on the code above for though?

It is a console.log statement.


var camper = "James";
var camper = "David";

cannot be overridden by let keyword because it shows an error?
but the code below:

var catName = "Oliver";
var catSound = "Meow!";

can be overridden by the let keyword without errors?

You cannot re-declare the same variable twice in the same scope with let.

As a general rule, you should never use var.

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