Skip to content

Instantly share code, notes, and snippets.

@tararoutray
Last active August 28, 2021 15:52
Show Gist options
  • Save tararoutray/c5bd18ed11a859a3c3d128a551c2e081 to your computer and use it in GitHub Desktop.
Save tararoutray/c5bd18ed11a859a3c3d128a551c2e081 to your computer and use it in GitHub Desktop.
// Let's declare a variable named "facebookURL"
const facebookURL = 'https://www.facebook.com/';
// If you try to change its value then the compiler or web browser will throw an error
facebookURL = 'facebook.com';
// Uncaught TypeError: Assignment to constant variable.
// Now let's declare a variable within a loop
for(const j = 0; j < 10; j++) {
// Variable "j" can be accessible within this loop
// But it will only be printed once
// i.e; 0. The rest values will not be assigned.
console.log(j);
// Uncaught TypeError: Assignment to constant variable after one loop.
}
// Now let's print this "j" outside the "for" loop
console.log(j);
// The compiler or web browser will throw an error if you try to print the value of "j" outside the "for" loop:
// Uncaught ReferenceError: j is not defined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment