Functional Programming

Major libraries supporting functional programming in JavaScript

We will be primarily using Ramda for our examples below.

Importing the library:

R = require('ramda');

Empty

Checking whether something is empty (an object or an array or a string):

> R.isEmpty({})
true
> R.isEmpty([])
true
> R.isEmpty('')
true

This function will appropriately return false in other cases:

> R.isEmpty(0)
false
> R.isEmpty(1)
false
> R.isEmpty(true)
false
> R.isEmpty(false)
false
> R.isEmpty(null)
false
> R.isEmpty(undefined)
false
> R.isEmpty(NaN)
false
> R.isEmpty({1: 2})
false
> R.isEmpty([1])
false
> R.isEmpty('a')
false