Skip to content

Instantly share code, notes, and snippets.

View michaelablackham's full-sized avatar

Michaela (Blackham) Lederman michaelablackham

View GitHub Profile
1. What is scope? Your explanation should include the idea of global vs. local scope.
- Scope is the way the the browser parses the information on the page. It is like a backward ladder that first looks
within the function, then steps back and looks within the parent, etc.
- global scope is a variable that is defined within the body or outside of a function and is then avaiable everywhere
within your site
- local scope is a variable defined within that current function. This can be the same variable from the body, but is
only relevent to that current function
2. Why are global variables avoided?
- Global variables should be avoided so that no unintended side effects happen within the code. This makes it available
everywhere in the code, which then becomes a bit difficult to maintain.
https://jsbin.com/sekihux/2/edit?js,output
https://jsbin.com/tevuri/2/edit?js,console
https://jsbin.com/mokuci/edit?js,console
https://jsbin.com/batotex/1/edit?js,console
https://jsbin.com/jazemoh/1/edit?js,console
https://jsbin.com/nunojug/1/edit?js,console
https://jsbin.com/geyuyek/1/edit?js,console
https://jsbin.com/calogo/1/edit?js,console
https://jsbin.com/gemexah/edit?js,console
https://jsbin.com/lixoqim/1/edit?js,console
https://jsbin.com/kuqosim/1/edit?js,console
https://jsbin.com/nezazu/1/edit?js,console
https://jsbin.com/juhojo/1/edit?js,console
function main() {
try {
doAllTheThings();
}
catch(e) {
console.error(e)
reportError(e);
}
}
function computeArea(width, height) {
return width*height;
}
// tests
function testComputeArea() {
var width = 3;
var height = 4;
var expected = 12;
@michaelablackham
michaelablackham / shouter
Created April 9, 2017 02:51
String Drills
function shouter(whatToShout) {
return whatToShout.toUpperCase() + '!!!';
}
/* From here down, you are not expected to
understand.... for now :)
Nothing to see here!
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">