Created
January 21, 2019 18:11
-
-
Save joey2031/424a9d51056471cb2fa9725aa2f5932b to your computer and use it in GitHub Desktop.
Hoisting in javascript created by joey2031 - https://repl.it/@joey2031/Hoisting-in-javascript
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>repl.it</title> | |
<link href="style.css" rel="stylesheet" type="text/css" /> | |
</head> | |
<body> | |
<script src="script.js"></script> | |
</body> | |
</html> |
This file contains 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
var x; | |
var y = 7; | |
console.log("The value of x is " + x); // prints undefied | |
console.log(`The value of y is ${y}`); // prints 7 | |
// prints undefied this is called hoisting, it brings the var z(the declraion) but not the assignment of 7 to the top. This is usless we do not want this. | |
console.log(`The value of z is ${z}`); | |
var z = 7; | |
// This is why let is better then var because it does not hoist the variables. | |
let a = 90; | |
let w; | |
console.log(`the value of w is ${w}`); | |
console.log(`The value of a is ${a}`); // prints 90 | |
console.log(`The value of b is ${b}`); //this will not print, instead it gives you a run time error. Also anything you put after this line will not execute because of the run time error. | |
let b = 70; |
This file contains 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
Empty file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment