files: notes.md
week: 1
step: 1
name: Week 1 Step 1
Week 1 Step 1
Git:
Run the following commands before starting:
In your main branch: git pull
to pull any updates.
Delete your previous branches locally git branch -d previousBranchName
, and remotely git push origin --delete previousBranchName
Change your branch to a new one for this step: git checkout -b week-1-step-5
git pull
again just in case.
What is JavaScript?
Before starting, let's look into all the things that make JavaScript stand out from other programming languages and determine what it can be used for.
What is Node?
Node.js is an open source runtime environment that will allow us to run our code outside of a web browser (i.e. no need for HTML, CSS to run the code).
Synchronous vs Asynchronous Functions
JavaScript is, by default, a synchronous language. This means that all the code in JS will be run line by line, block by block.
But what happens when a part of your code has to wait for another part? Let's say one of your functions is writing code to a database, and the next function needs something from that database. Since writing to a database can take time, if both functions are synchronous it is very possible that your second function will try to access data before the first function was able to complete executing.
This calls for the need to have async functions, that can wait for something to be completed before they run a piece of code.
How do we make an asynchronous function?
// typical synchronous function definition:
function function_1() {
// ....contents....
}
// async function definition:
async function function_2() {
// ....contents....
}
We will elaborate on how to make the async function wait in the future. These definitions are only to let the program know that the function function_2
is not synchronous.
Review:
Write a javascript program with the function definitions for an asynchronous function and a synchronous function.
Create a notes.md file and describe what the difference between asynchronous and synchronous functions is in your own words and come up with an example of when you would use either. Add your code to the notes.md, and make a pull request to close this issue and continue.