Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

README.md

Reading Material JavaScript2 Week 3

Agenda

These are the topics for week 3:

  1. Scope
    • Global vs. local (function and block)
    • Const and let
  2. Hoisting
    • What is it
    • When does it happen
    • Why do we need to know it?
  3. Closures
  4. Thinking like a programmer II

1. Scope

On of the central concepts in programming is the idea of context: the meaning of any particular thing is only determined in relation to its direct surroundings. Let's take language for example. If I say the following sentence:

I never said she stole my money.

Reading this it's not obvious how to interpret what the situation is about. Depending on the emphasis of the words it could mean any of the following:

  • I never said she stole my money.
  • I never said she stole my money.
  • I never said she stole my money.
  • I never said she stole my money.
  • I never said she stole my money.
  • I never said she stole my money.
  • I never said she stole my money.

It depends on context for me to know what really happened.

Let's draw the line to programming. Within any program there is a lot happening. But not everything is related to each other; some functions don't depend on other functions or variables

scope has to do with "where we can access variables from"

For further research, check out the following:

Global vs. local (function and block)

Const and let

Quick refresher: Variables are used to store information to be referenced and manipulated in a computer program. They also provide a way of labeling data with a descriptive name, so our programs can be understood more clearly by the reader and ourselves. It is helpful to think of variables as containers that hold information. Their sole purpose is to label and store data in memory. This data can then be used throughout your program.

In JavaScript we define them using the keyword var:

var

2. Hoisting

If you look up the term "hoisting" in any dictionary, you'll find something like this:

"To raise [something] by means of ropes and pulleys"

A simple example of hoisting is the hoisting of a flag on a pole. You pull on the rope and slowly but surely the flag gets raised up.

What is it

In JavaScript, hoisting refers to

When does it happen

Why do we need to know it?

When you execute your JavaScript code, the interpreter goes through the code twice. The first time is called the compile-time, which is when your code is made ready to be executed: there will be safety checks, small optimizations and making sure the syntax is written correctly.

The second time is called run-time, which is where it actually executes your code by going through it line by line, doing the assignments, calling the functions, etc.

Hoisting happens during compile-time.

3. Closures

Simply put, a closure is a function that is defined inside another function.

For further study please check the following resources:

4. Thinking like a programmer II

Becoming a good developer doesn't mean being good at any particular programming language: as a matter of fact, the language doesn't matter much.

There are only a handful of core concepts

This is the secret behind being a good developer: if you understand the concept, structure and principles of what makes a software program work, it doesn't matter in what way (syntax) it's written.

Finished?

Are you finished with going through the materials? High five! If you feel ready to get practical, click here.