Skip to content

Instantly share code, notes, and snippets.

@ksk5280
Last active May 13, 2016 04:32
Show Gist options
  • Save ksk5280/85d4c5997e25e1063b42c96c4bb2ff74 to your computer and use it in GitHub Desktop.
Save ksk5280/85d4c5997e25e1063b42c96c4bb2ff74 to your computer and use it in GitHub Desktop.
Speaking Javascript

Chapters 3, 15, 16, 17

  • Chapter 3: The Nature of JavaScript

    • Interesting summary
  • Chapter 15: Functions

    • Hoisting means “moving to the beginning of a scope.” Function declarations are hoisted completely, variable declarations only partially. Hoising allows you to call a function before it has been declared.
    • Interesting: This book says that function declarations are better than function expressions because they are hoisted and have a name, but the jQuery fundamentals and this blog said that function declarations are confusing because of the hoisting and function expressions are favored. Perhaps named function expressions are the way to go?
      • On a later thought, after working on Idea Box and separating functions into different files for organization (which I'm not sure whether I did it in a good way or not), but it seems like if you happened to call a function in a different file than where it's declared you might not know what order the files will end up being in, so it seems like using declared functions that are hoisted would make sure that you don't run into problems.
  • Chapter 16: Variables: Scopes, Environments, and Closures

    • It's interesting that variables in JS are function scoped, not block scoped.
    • Many style guides recommend putting variables at the beginning of a function to avoid being tricked by hoisting.
    • You can create global functions by making assignments without using var, but strict mode will throw an error.
    • Immediately invoked function expressions are a way of defining a function to restrict the scope of a variable.
    • There are a lot of disadvantages to using global variables (less robust, likely to cause confusion and overlapping of variable naming), so it is best practice to not use them.
  • Chapter 17: Objects and Inheritance

    • Avoid the constructor when creating a new object.
    • Nested functions don't have access to 'this', but there are three ways shown for how to get around the problem.
  • I skimmed a lot of ch. 17 because it was so long and I felt like I wasn't getting a lot out of reading. I think after using more JavaScript some of these things might make more sense to read about, but at this time it wasn't that useful for me because I don't have enough context. I definitely learn more by doing projects rather than reading.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment