JavaScript Function Snippets

The JavaScript snippet collection contains a wide variety of ES6 helper functions. It includes helpers for dealing with primitives, arrays and objects, as well as algorithms, DOM manipulation functions and Node.js utilities.

  • Curry function

    JavaScript, Function

    Curries a function.

  • Iterate n times

    JavaScript, Function

    Iterates over a callback n times.

  • Argument coalescing factory

    JavaScript, Function

    Customizes a coalesce function that returns the first argument which is true based on the given validator.

  • Convert function to variadic

    JavaScript, Function

    Changes a function that accepts an array into a variadic function.

  • You've probably come across the double negation operator (!!) before, but do you know what it does?

  • Call or return

    JavaScript, Function

    Calls the argument if it's a function, otherwise returns it.

  • Check property

    JavaScript, Function

    Creates a function that will invoke a predicate function for the specified property on a given object.

  • Debounce function

    JavaScript, Function

    Creates a debounced function that delays invoking the provided function until at least ms milliseconds have elapsed since its last invocation.

  • Creates a generator, that keeps producing new values until the given condition is met.

  • Creates a generator, that keeps producing new values as long as the given condition is met.

  • What is an IIFE in JavaScript?

    JavaScript, Function

    An Immediately Invoked Function Expression (IIFE) is a JavaScript trick that trips up many developers. Here's what you need to know.

  • Attempt invoking a function

    JavaScript, Function

    Attempts to invoke a function with the provided arguments, returning either the result or the caught error object.

  • Call functions with context

    JavaScript, Function

    Given a key and a set of arguments, call them when given a context.

  • Get function name

    JavaScript, Function

    Logs the name of a function.

  • Value is function

    JavaScript, Type

    Checks if the given argument is a function.