Skip to content

Commit

Permalink
Grammar changes to scope.md
Browse files Browse the repository at this point in the history
  • Loading branch information
miparnisari committed Nov 14, 2016
1 parent a6c6637 commit 82fc5fa
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions workflow/scope.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Setup the correct variables scope.
# Setup the correct scope for variables.

If you declare a global variable but you only use it in a little part of your code, then you are keeping in memory the variable all time but.
If you declare a global variable but you only use it in a small part of your code, then you are keeping the variable in memory all the time.

When a variable is referenced, Javascript hunts it down by looping through the different members of the scope chain. This scope chain is the set of variables available within the current scope, and across all major browsers it has at least two items: a set of local variables and a set of global variables.

Simply put, the deeper the engine has to dig into this scope chain, the longer the operation will take. It first goes through the local variables starting with this, the function arguments, then any locally defined variables, and afterwards iterates through any global variables.
Simply put, the deeper the engine has to dig into this scope chain, the longer the operation will take. It first goes through the local variables starting with `this`, the function arguments, then any locally defined variables, and afterwards it iterates through global variables.

**Continue reading: ES2015 tips**

Notes that with ES2015, you can use `const` and `let` as well.
With ES2015, you can use `const` and `let`.

`const` means that the variable can’t be reassigned. (Not to be confused with immutable values. Unlike true immutable datatypes such as those produced by Immutable.js and Mori, a `const` object can have properties mutated.):

Expand All @@ -32,6 +32,4 @@ const objt = {}

`var` is now the weakest signal available when you define a variable in JavaScript. The variable may or may not be reassigned, and the variable may or may not be used for an entire function, or just for the purpose of a block or loop.

You need to be reassign? then `let`, else `const`.

Another important approach: If you need to deallocate a value by unsetting it, you may consider `let` over `const`.
So if you need to allow the variable to be reassigned, use `let`, otherwise use `const`. Also, if you need to deallocate a value by unsetting it, you may consider `let` over `const`.

0 comments on commit 82fc5fa

Please sign in to comment.