first class functions in JavaScript

First class functions are functions that are treated like any other variable. This allows higher-order functions to be created.

higher-order functions

A higher-order function can take in multiple functions and/or return a function.

An example that takes in a function could be filter() to remove all shirts from an array of clothes.

JavaScript

const clothes = ['shirt', 'sweater', 'pants', 'pants', 'sweater', 'shirt'];
const filteredClothes = clothes.filter(item => item !== 'shirt');

console.log(filteredClothes);
// (4) ["sweater", "pants", "pants", "sweater"]

An example of a function being returned could be one that takes in a number and returns a function that also takes in a number and adds both of them.

JavaScript

function add(a) {
    return function (b) {
        return a + b;
    };
}

const add10 = add(10);

console.log(add10(20)); // 30
javascript
primitives vs objects

Primitives are immutable and passed by value. Objects are mutable and stored by reference.

javascript
is JavaScript synchronous, asynchronous or single-threaded

JavaScript is synchronous and single-threaded with capability to do asynchronous calls.