From 110b3d6efd2b836c4a449a8b0d889c7e512a5bb4 Mon Sep 17 00:00:00 2001 From: Markus Amalthea Magnuson Date: Thu, 18 Apr 2013 22:29:31 +0200 Subject: [PATCH 1/6] Remove extra space in code comments. --- page/javascript-101/scope.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/page/javascript-101/scope.md b/page/javascript-101/scope.md index c4f91849..81c97b3d 100644 --- a/page/javascript-101/scope.md +++ b/page/javascript-101/scope.md @@ -67,7 +67,7 @@ function outer() { console.log( x ); } - inner(); // 5 + inner(); // 5 } ``` @@ -82,7 +82,7 @@ function outer() { var y = 10; } - inner(); // 5 + inner(); // 5 console.log( y ); // ReferenceError: y is not defined } From b28c72a39b8c02ee891903a9b4d28bd6049924b4 Mon Sep 17 00:00:00 2001 From: Markus Amalthea Magnuson Date: Thu, 18 Apr 2013 22:29:52 +0200 Subject: [PATCH 2/6] Remove incorrect end parenthesis. --- page/javascript-101/scope.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/page/javascript-101/scope.md b/page/javascript-101/scope.md index 81c97b3d..039713f1 100644 --- a/page/javascript-101/scope.md +++ b/page/javascript-101/scope.md @@ -40,7 +40,8 @@ If you declare a variable and forget to use the `var` keyword, that variable is ``` function myFunc() { x = 5; -}); +}; + console.log( x ); // 5 ``` From 84037dcc00a4a39d1d5cd647a850b51e093fb72c Mon Sep 17 00:00:00 2001 From: Markus Amalthea Magnuson Date: Thu, 18 Apr 2013 22:30:03 +0200 Subject: [PATCH 3/6] More space. --- page/javascript-101/scope.md | 1 + 1 file changed, 1 insertion(+) diff --git a/page/javascript-101/scope.md b/page/javascript-101/scope.md index 039713f1..f4d12717 100644 --- a/page/javascript-101/scope.md +++ b/page/javascript-101/scope.md @@ -28,6 +28,7 @@ JavaScript also creates a __Local Scope__ inside each function body. For example function myFunc() { var x = 5; }; + console.log( x ); // ReferenceError: x is not defined ``` From 326766e7d57dfed7349fdbf635ac4007aec90d9d Mon Sep 17 00:00:00 2001 From: Markus Amalthea Magnuson Date: Thu, 18 Apr 2013 22:30:23 +0200 Subject: [PATCH 4/6] Scope only needs quotation marks the first time. --- page/javascript-101/scope.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/page/javascript-101/scope.md b/page/javascript-101/scope.md index f4d12717..889bf94d 100644 --- a/page/javascript-101/scope.md +++ b/page/javascript-101/scope.md @@ -6,7 +6,7 @@ attribution: - jQuery Fundamentals --- -"Scope" refers to the variables that are available to a piece of code at a given time. A lack of understanding of scope can lead to frustrating debugging experiences. The idea of "scope" is that it's where certain functions or variables are accessible from in our code, and the context in which they exist and are executed in. +"Scope" refers to the variables that are available to a piece of code at a given time. A lack of understanding of scope can lead to frustrating debugging experiences. The idea of scope is that it's where certain functions or variables are accessible from in our code, and the context in which they exist and are executed in. There are two types of scopes in JavaScript: global and local. Let's talk about each of them in turn. From 87a666d7acd29f42491fdec1519aa4ee1a66daad Mon Sep 17 00:00:00 2001 From: Markus Amalthea Magnuson Date: Thu, 18 Apr 2013 22:30:38 +0200 Subject: [PATCH 5/6] Fix typos. --- page/javascript-101/scope.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/page/javascript-101/scope.md b/page/javascript-101/scope.md index 889bf94d..81bea703 100644 --- a/page/javascript-101/scope.md +++ b/page/javascript-101/scope.md @@ -48,7 +48,7 @@ console.log( x ); // 5 This is a bad idea. Any variable that is global can have its value changed by any other parts of a program or any other script. This is undesirable, as it could lead to unforseen side effects. -Secondly, Immediately-Invoked Funcion Expressions provide a way to avoid global variables. You'll see many libraries such as jQuery often use these: +Secondly, Immediately-Invoked Function Expressions provide a way to avoid global variables. You'll see many libraries such as jQuery often use these: ``` (function() { @@ -57,7 +57,7 @@ Secondly, Immediately-Invoked Funcion Expressions provide a way to avoid global })(); ``` -Wrapping everything in a function which is then immediately invoked means all the variables within that function are bound to the _local scope_. At the very end you can then expose all your methods by binding the `jQuery` object to the `window`, the _global object_. To read more about Immediatly-Invoked Functions, check out Ben Alman's [Immediately-Invoked Function Expression](http://benalman.com/news/2010/11/immediately-invoked-function-expression/) article. +Wrapping everything in a function which is then immediately invoked means all the variables within that function are bound to the _local scope_. At the very end you can then expose all your methods by binding the `jQuery` object to the `window`, the _global object_. To read more about Immediately-Invoked Functions, check out Ben Alman's [Immediately-Invoked Function Expression](http://benalman.com/news/2010/11/immediately-invoked-function-expression/) article. Because local scope works through functions, any functions defined within another have access to variables defined in the outer function: From 2e1545639055f1bd192047c0f2aa5bcbad9a74e8 Mon Sep 17 00:00:00 2001 From: Markus Amalthea Magnuson Date: Thu, 18 Apr 2013 22:30:50 +0200 Subject: [PATCH 6/6] Sentencize code comment. --- page/javascript-101/scope.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/page/javascript-101/scope.md b/page/javascript-101/scope.md index 81bea703..e88e175d 100644 --- a/page/javascript-101/scope.md +++ b/page/javascript-101/scope.md @@ -52,8 +52,8 @@ Secondly, Immediately-Invoked Function Expressions provide a way to avoid global ``` (function() { - var jQuery = { /* all my methods go here */ }; - window.jQuery = jQuery. + var jQuery = { /* All my methods go here. */ }; + window.jQuery = jQuery; })(); ```