Skip to content

Instantly share code, notes, and snippets.

View dhoel's full-sized avatar

Dave Hoel dhoel

View GitHub Profile
{
"env": {
"browser": true,
"commonjs": true,
"es6": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaFeatures": {
"experimentalObjectRestSpread": true,
@dhoel
dhoel / gist:21997bf751aaf657617b083534252881
Created February 12, 2017 21:43
Event Listener Drills
https://jsbin.com/cubuhap/1/edit?js,output
https://jsbin.com/cubuhap/1/edit?js,output
https://jsbin.com/dunutu/2/edit?js,output
https://jsbin.com/laweco/edit?js,console
https://jsbin.com/zihuji/edit?js,console
https://jsbin.com/jugahoy/edit?html,js,console
https://jsbin.com/cejemuv/edit?js,console
What is scope?
> Scope, or Variable Scope, is the idea regarding in which part of a program a given variable can be referenced or changed.
In Javascript there are two scopes, Global and Local. Local scope is within a function so any variable that is declared
(var varOne;) within a funtion can only be referenced or changed from inside that function - that variable's scope is local
to that function. Global scope is throughout a program, outside of functions as well as within any functions. A variable
that is declared outside of any functions has global scope and can be referenced or changed in any part of the program. Also,
when a variable is assigned a value without being specifically declared (varOne = 'value';) from inside a function, that variable
has global scope as well.
Why are global variables avoided?
https://jsbin.com/regeya/edit?js,console
https://jsbin.com/hefucod/edit?js,console
https://jsbin.com/ketofe/edit?js,console
https://jsbin.com/worimex/edit?js,console
https://jsbin.com/zeleya/edit?js,console
https://jsbin.com/tumomu/edit?js,console
https://jsbin.com/hejebub/edit?js,console,output
https://jsbin.com/rawepuk/edit?js,console,output
https://jsbin.com/jexoda/edit?html,js,console
https://jsbin.com/juheze/edit?js,console
https://jsbin.com/tuqokec/edit?js,console
https://jsbin.com/ceribe/edit?js,console
https://jsbin.com/menuhu/edit?js,console
https://jsbin.com/yebiqa/edit?js,console