Skip to content

Instantly share code, notes, and snippets.

@NimaBoscarino
Created January 9, 2019 03:47
Show Gist options
  • Save NimaBoscarino/840af29dd362c8e73ca0f9eae8aa5e5e to your computer and use it in GitHub Desktop.
Save NimaBoscarino/840af29dd362c8e73ca0f9eae8aa5e5e to your computer and use it in GitHub Desktop.
Scope!
//1. nothing
// 2.
console.log('Hey there')
// 3. Hey there, new line, goodbye
console.log('Hey there')
console.log('Goodbye')
// 4. Goodbye, Hey there
function sayHello () {
console.log('Hey there')
}
console.log('goodbye')
sayHello()
// 5. Tyson
var bestFriend = 'Tyson'
function sayNameOfFriend() {
console.log(bestFriend)
}
sayNameOfFriend()
// 5. Hussain
var bestFriend = 'Tyson'
function sayNameOfFriend() {
bestFriend = 'Hussain'
console.log(bestFriend)
}
sayNameOfFriend()
// 6. Tyson, Hussain
var bestFriend = 'Tyson'
function sayNameOfFriend() {
bestFriend = 'Hussain'
console.log(bestFriend)
}
console.log(bestFriend)
sayNameOfFriend()
// 6. Tyson, Hussain, Hussain || Tyson, Hussain, Tyson ?
var bestFriend = 'Tyson'
function sayNameOfFriend() {
var bestFriend = 'Hussain'
console.log(bestFriend)
}
console.log(bestFriend)
sayNameOfFriend()
console.log(bestFriend)

Goals:

  1. Read code
    1. As a general programmer
    2. As a JAVASCRIPT programmer
  • read and evaluate code in our heads
    • not just from top to bottom, but as a computer would run it
  1. A rudimentary understanding of SCOPES
  • scope chain (call stack)
    • identify different levels of scope

We used Javascript Tutor (http://pythontutor.com/javascript.html#mode=edit)

Take a look at other instructor's lecture notes as well! There's tons of great stuff on Compass :)

Here are some examples from the last time I did this lecture: https://github.com/NimaBoscarino/scope-notes

Cheers,

Nima

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment