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
| 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. |
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
| https://jsbin.com/sekihux/2/edit?js,output | |
| https://jsbin.com/tevuri/2/edit?js,console | |
| https://jsbin.com/mokuci/edit?js,console |
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
| 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 |
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
| function main() { | |
| try { | |
| doAllTheThings(); | |
| } | |
| catch(e) { | |
| console.error(e) | |
| reportError(e); | |
| } | |
| } |
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
| function computeArea(width, height) { | |
| return width*height; | |
| } | |
| // tests | |
| function testComputeArea() { | |
| var width = 3; | |
| var height = 4; | |
| var expected = 12; |
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
| function shouter(whatToShout) { | |
| return whatToShout.toUpperCase() + '!!!'; | |
| } | |
| /* From here down, you are not expected to | |
| understand.... for now :) | |
| Nothing to see here! |
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
| <!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"> |
NewerOlder