Created
February 6, 2019 00:01
-
-
Save NimaBoscarino/fcf2d80177bc4986f138e5b856bc2832 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
// little snippets of code | |
// interpret the code ourselves | |
// Snippet 1 -- nothing happens, we think | |
// Snippet 2 -- hey there | |
console.log('hey there') | |
// Snippet 3 -- hey, goodbye | |
console.log("Hey there") | |
console.log("Goodbye") | |
// Snippet 4 -- goodbye, hey there | |
function sayHello() { | |
console.log("Hey there") | |
} | |
console.log("goodbye") | |
sayHello(); | |
// Snippet 5 - Tyson | |
var bestFriend = 'Tyson' | |
function sayNameOfFriend() { | |
console.log(bestFriend) | |
} | |
sayNameOfFriend() | |
// Snippet 6 -- Hussain | |
var bestFriend = 'Tyson' | |
function sayNameOfFriend() { | |
bestFriend = 'Hussain' | |
console.log(bestFriend) | |
} | |
sayNameOfFriend() | |
// Snippet 7 - Tyson, Hussain | |
var bestFriend = 'Tyson' | |
function sayNameOfFriend() { | |
bestFriend = 'Hussain' | |
console.log(bestFriend) | |
} | |
console.log(bestFriend) | |
sayNameOfFriend() | |
// Snippet 8 | |
//- Tyson, Hussain, Tyson <--- CORRECT | |
//- *, Hussain, Hussain | |
// the variables are completely separate. | |
// "separate scopes" | |
var bestFriend = 'Tyson' | |
function sayNameOfFriend() { | |
var bestFriend = 'Hussain' | |
console.log(bestFriend) | |
} | |
console.log(bestFriend) | |
sayNameOfFriend() | |
console.log(bestFriend) | |
// Snippet 9 | |
var bestFriend = 'Tyson' | |
var food = 'avocado' | |
function sayNameOfFriend() { | |
console.log(bestFriend) | |
sayFood() | |
} | |
function sayFood() { | |
console.log(food) | |
} | |
sayNameOfFriend() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment