Skip to content

Instantly share code, notes, and snippets.

View sandrabosk's full-sized avatar
👩‍💻
Always a student, never a master. Have to keep moving forward. ~C.Hall

Aleksandra Bošković sandrabosk

👩‍💻
Always a student, never a master. Have to keep moving forward. ~C.Hall
  • Ironhack
View GitHub Profile

As JS is single-threaded, only one operation can occure at the time. To be able to perform multiple operations at the same time but to also keep a track of their order of execution, we have to use different techniques to make sure these operations don't block the main thread and program execution. These are callbacks, event, promises and async/await. They allow us to run code asynchronously without blocking the program execution.

Callbacks to promises (and dash of async-await)

Let's write a function whose execution time will depend on some external influence - in this case the setTimeout() method:

function printString(str) {
  setTimeout(() => {
 console.log(str);

Contributing guidelines

The entire development efforts of the project should be concentrated in the official Github repository for irongenerator.

Note we have the Code of Conduct. Please follow it in all your interactions with the project.

We should follow the common procedure/workflow as described below:

(1) Open an issue
// ITERATION 1
function updateSubtotal(product) {
console.log('Calculating subtotal, yey!');
// Get DOM elements that hold price and quantity
const price = product.querySelector('.price span');
const quantity = product.querySelector('.quantity input');
// Extract values from DOM elements
const priceValue = parseFloat(price.innerText);
// Example 1:
const productsAsStrings = [
'iphone', 'mug', 'hat'
]
const deleteProd = toBeDeleted => {
const filteredArr = productsAsStrings.filter(el => el !== toBeDeleted)
return filteredArr;
}

Types of components in React - cheatsheet

Function component

  • [for now] has no state
  • has props (props.something or ({something}) when accessing it)
import React from 'react';

// function component - traditional
// THIS FILE ALSO HAS EXAMPLE OF HOW TO USE MATH.FLOOR(), MATH.ROUND() AND MATH.CEIL() AND TOFIXED() (FROM THE LESSON ADVANCED NUMBERS)
There are two kinds of data types in JavaScript:
- primitives or primitive values and
- objects or non-primitive values.
a primitive (a.k.a. primitive value or primitive data type) is any data that is not an object and has no methods
There are 6 primitive data types:
// We use variables to store some information. We can imagine them as some kind of boxes,
// or storages, in which we place some data.
// To be able to re-access this data (to be able to reference them), we need to name them somehow.
// So we can say that varibles (storages) are named or we can say labeled.
// 3 ways to declare variables in JS:
// var
// let
  1. Create variables with your first name, last name and age.

  2. Make the first letters of your first and last name capitalized.

  3. Concatenate your first and last name (after capitalizing them) to give your full name.

  4. Use console.log() method to output the sentence with the following structure: My name is __________ and I am _____ years old.

// ************************************
// ************ BOOLEAN ***************
// ************************************
Can have 2 values:
- true
- false
We will heavily use booleans within conditional statements and for that purpose we need to learn
about logical operators: OR (||), AND (&&), NOT (!).
console.log(true && false); // ==> false
console.log(11 % 3 === 2); // ==> true
console.log(false || true); // ==> true
console.log(!true || false); // ==> false
console.log(17 == '17'); // ==> true
console.log(123 === '123'); // ==> false
const statement = 'I love JavaScript!';
const subStatement = statement.substr(2, 9);
console.log(statement); // I love JavaScript!