Scope and global and local variables

Dear members and tutors!

I was going through the scope section in JS and at the end of the section a question came up.
I don`t think I read about this.

Does local variable override global variables? or vice-versa?

Thank you, Zsolt

neither, these variable co-exists. But if a local and global variable with the same name exists, the local variable is used:

const x = 3;

const example = () => {
  const x = 5;
  console.log(x); // log: 5, local variable
}

example();
console.log(x); // logs: 3
1 Like