Skip to content

Instantly share code, notes, and snippets.

@emabeee
emabeee / Back End Development and APIs.md
Last active June 25, 2022 20:16
"Managing Packages with NPM", "Basic Node and Express", and "MongoDB and Mongoose"

Managing Packages with NPM

https://boilerplate-npm.emabeee.repl.co

How to Use package.json, the Core of Any Node.js Project or npm Package

"author": "emalie",

Add a Description to Your package.json

@emabeee
emabeee / postman.md
Created June 12, 2022 00:25
Testing APIs

API: Awesome JSON Datasets, Emojis

https://api.github.com/emojis

pm.test("Status test", function () {
    pm.response.to.have.status(200);
});

Results: passed

@emabeee
emabeee / codewars.md
Last active June 11, 2022 22:40
Remove First and Last Character

Remove First and Last Character

It's pretty straightforward. Your goal is to create a function that removes the first and last characters of a string. You're given one parameter, the original string. You don't have to worry with strings with less than two characters.

function removeChar(str) {
    return str.slice(1, str.length - 1)
}

Array plus array

@emabeee
emabeee / javascript.activities.md
Last active June 11, 2022 21:26
JavaScript activities ("Hello, World", "Lucian's Luscious Lasagna", "Annalyn's Infiltration")

"Hello, World!"

Write a function that returns the string "Hello, World!". Run the test suite and make sure that it succeeds. Submit your solution and check it at the website.

export function hello() {
  return 'Hello, World!';
}
console.log('Debug message');

1. Fetch

Network Requests: how javascript loads new information when it is needed.

AJAX: Asynchronous JavaScript And XML; umbrella term for network requests from JavaScript.

There are multiple ways to send a network request and get information from the server.

  • The fetch() method
    • modern and versatile
  • The basic syntax: let promise = fetch(url, [options])
@emabeee
emabeee / Asynchronous.Programming.md
Last active June 4, 2022 00:03
Asynchronous Programming, chapter 11.

Asynchronous Programming

Callback Function: The action is started, and when it finishes, the callback function is called with the result.

Example: setTimeout function waits a given number of milliseconds (a second is a thousand milliseconds) and then calls a function. setTimeout(() => console.log("Tick"), 500);

  • The defineRequestType function defines a new type of request.
  • A function doing asynchronous work typically returns before the work is done, having arranged for a callback to be called when it completes. So we need some asynchronous mechanism—in this case, another callback function—to signal when a response is available
  • Any function that calls a function that works asynchronously must itself be asynchronous, using a callback or similar mechanism to deliver its result. * more involved and error-prone
@emabeee
emabeee / callbacks.promises.examples.and.guide.md
Last active June 3, 2022 23:14
"Callbacks and Promises | Explained with Examples" and "A Guide to JavaScript Callbacks and Promises."

Callbacks and Promises | Explained with Examples

To implement asynchronous code we use callbacks and promises in JavaScript.

Callbacks:

  • Functions that are passed inside the arguments of other functions.
  • used to acquire control over the sequence of execution.
  • executed on the basis of the sequence that they are invoked, not on the sequence in which they are defined.
@emabeee
emabeee / callbacks.asynchronous.promises.async.md
Last active June 3, 2022 21:38
JavaScript Callbacks, Asynchronous JavaScript, JavaScript Promises, and JavaScript Async.

Callbacks

A callback is a function passed as an argument to another function. This technique allows a function to call another function. A callback function can run after another function has finished. JavaScript functions are executed in the sequence they are called. Not in the sequence they are defined.

Sequence Control Sometimes you would like to have better control over when to execute a function. Suppose you want to do a calculation, and then display the result. You could call a calculator function (myCalculator), save the result, and then call another function (myDisplayer) to display the result. Or, you could call a calculator function (myCalculator), and let the calculator function call the display function (myDisplayer) The problem with the first example above, is that you have to call two functions to display the result. The problem with the second example, is that you cannot prevent the calculator function from displaying the result. This is when you use a callback.

function myDispla
@emabeee
emabeee / callbacks.promises.a.md
Last active June 3, 2022 06:06
Callbacks and promises, A. 'JavaScript Async/Await Tutorial – Learn Callbacks, Promises, and Async/Await in JS by Making Ice Cream'.

What is Asynchronous JavaScript?

The theory of async JavaScript helps you break down big complex projects into smaller tasks.

Synchronous vs Asynchronous JavaScript

In a synchronous system, tasks are completed one after another. Like you have one hand to complete 10 tasks so you have to do them one at a time. JavaScript is by default Synchronous [single threaded] – one thread means one hand with which to do stuff. Example: Synchronous system, three images are in the same lane. One can't overtake the other. The race is finished one by one. If image number 2 stops, the following image stops.

  • To test a synchronous system, write this code in JavaScript:
console.log(" I ");
@emabeee
emabeee / debugging.md
Last active September 10, 2025 12:08
Complete the "Debugging" exercises (Links to an external site.) in the "JavaScript Algorithms and Data Structures" section.

Use the JavaScript Console to Check the Value of a Variable

Both Chrome and Firefox have excellent JavaScript consoles, also known as DevTools, for debugging your JavaScript. You can find Developer tools in your Chrome's menu or Web Console in Firefox's menu. If you're using a different browser, or a mobile phone, we strongly recommend switching to desktop Firefox or Chrome. The console.log() method, which "prints" the output of what's within its parentheses to the console, will likely be the most helpful debugging tool. Placing it at strategic points in your code can show you the intermediate values of variables. It's good practice to have an idea of what the output should be before looking at what it is. Having check points to see the status of your calculations throughout your code will help narrow down where the problem is. Here's an example to print the string Hello world! to the console: console.log('Hello world!'); Use the console.log() method to print the value of the variable a where noted in t