Skip to content

Instantly share code, notes, and snippets.

@tararoutray
Last active August 28, 2021 15:43
Show Gist options
  • Save tararoutray/990247a542425d8efde7d4513c046d29 to your computer and use it in GitHub Desktop.
Save tararoutray/990247a542425d8efde7d4513c046d29 to your computer and use it in GitHub Desktop.
// Let's declare a variable named "emailAddress"
let emailAddress = 'someone@example.com';
// If accidentally we redeclare anathor variable with the same name,
// then the compiler will throw an error, which is indeed a great practice.
let emailAddress = 'abc';
// Uncaught SyntaxError: Identifier 'emailAddress' has already been declared
// Now let's declare a variable within a loop
for(let i = 0; i < 10; i++) {
// Variable "i" can be accessible within this loop
console.log(i);
}
// Now let's print this "i" outside the "for" loop
console.log(i);
// The compiler or web browser will throw an error if you try to print the value of "i" outside the "for" loop:
// Uncaught ReferenceError: i is not defined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment