Es 6 question declaration of variable

Desc say this
let camper = ‘James’;
let camper = ‘David’; // throws an error

my code :-

let catName = “Duffyf”;
let quote;
function catTalk() {
“use strict”;

catName = “Oliver”;
quote = catName + " says Meow!";

}
catTalk();

why this is not giving any error i have declared catName already ???

when you declare a variable it means using the let keyword. After you declare the variable you can change its value multiple times. let camper = 'David'; throws an error because the variable camper has laready been declared in the line above with let.
When you do catName = “Oliver”; you are just changing the value of the variable, not declaring it again.

2 Likes

first of all you declare camper and second time you re-declare it’s but in the same scope you can’t declare a same variable with the same name two times because the are in the same scope

in the seconde case you declare catName in the globale scope anything declared here is accessible in any function function but the opposite is not possible

hope this was helpful

thanks for explaing it I got you point thanks once again