mirror of
https://github.com/Stone-Red-Code/website.git
synced 2026-09-04 23:44:11 +02:00
content(resources): clean up markdown files, headings & codeblocks
This commit is contained in:
@@ -16,7 +16,7 @@ completed at a later time. Much like in real life, when you create a promise, yo
|
||||
to fulfill that promise. However, sometimes things go wrong where you can no longer fulfill
|
||||
a promise you made. This is essentially the main idea behind how promises work in javascript.
|
||||
|
||||
### Basics
|
||||
## Basics
|
||||
|
||||
When you create a Promise or call a function that returns a Promise in Javascript, you're left
|
||||
with an object that can either resolve into the actual value that you were promised, or it
|
||||
@@ -24,7 +24,7 @@ can reject and leave you with an error for why that promise failed.
|
||||
|
||||
We can access these values using the `.then` and `.catch` methods on the `Promise` object respectively.
|
||||
|
||||
### A Simple Example
|
||||
## A Simple Example
|
||||
|
||||
First, let's explore a bit of a made-up example. Imagine we have a promise-returning function
|
||||
called `getMembers` that retrieves all the members in a discord server. When we execute this
|
||||
@@ -50,7 +50,7 @@ getMembers("The Programmers Hangout").then(members => {
|
||||
|
||||
This way we are able to make sure that we only try to `console.log` when the `getMembers` function has resolved and ready to be used.
|
||||
|
||||
### Beginner Mistakes
|
||||
## Beginner Mistakes
|
||||
|
||||
Promises are possibly the #1 most common source of confusion for beginners. In order
|
||||
to avoid falling in pitfalls yourself, you have to remember 2 things about Javascript when
|
||||
@@ -85,7 +85,7 @@ getWeather("Los Angeles").then(weather => {
|
||||
});
|
||||
```
|
||||
|
||||
### Real World Example
|
||||
## Real World Example
|
||||
|
||||
Here is a real function that gets character information from the Rick and Morty API.
|
||||
You can try it in your browser if you want to test it out.
|
||||
|
||||
@@ -12,8 +12,6 @@ external_resources:
|
||||
href: "https://www.freecodecamp.org/news/spread-operator-and-rest-parameter-in-javascript-es6-4416a9f47e5e/"
|
||||
---
|
||||
|
||||
# An overview of the spread operator
|
||||
|
||||
Spread operator (or spread syntax) is a powerful feature in Javascript which allows you to do such things as merging or copying objects, expanding an array into function arguments and a lot more. In this post, we are going to cover most of its use-cases.
|
||||
|
||||
## Copying an object
|
||||
|
||||
@@ -5,8 +5,6 @@ created_at: "2019/10/06"
|
||||
title: Variables
|
||||
---
|
||||
|
||||
## Variables
|
||||
|
||||
A `variable` in Javascript is a "named container" that can hold data. Variables are declared by giving them a name and a value - the `name` allows you to reference the variable throughout your program, and the `value` is the current value the variable represents.
|
||||
|
||||
Variables can be defined in the following ways:
|
||||
@@ -117,15 +115,15 @@ console.log(myVar); // 'test'
|
||||
This is fixed using `let`
|
||||
|
||||
```js
|
||||
for(let i = 0; i < 5; i++) {
|
||||
for (let i = 0; i < 5; i++) {
|
||||
console.log(i);
|
||||
}
|
||||
console.log(i); // Error: i is undefined
|
||||
|
||||
if (true) {
|
||||
let myVar = 'test';
|
||||
let myVar = "test";
|
||||
}
|
||||
console.log(myVar) // Error: myVar is undefined
|
||||
console.log(myVar); // Error: myVar is undefined
|
||||
```
|
||||
|
||||
However, if the above code was in a function, this would not be the case. In the case of a function, the variable will be scoped to the given function, and not accessible outside it. Eg:
|
||||
|
||||
Reference in New Issue
Block a user