Last active
August 28, 2021 15:52
-
-
Save tararoutray/c5bd18ed11a859a3c3d128a551c2e081 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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