JavaScript 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.

  • Number is prime

    Checks if the provided integer is a prime number.

    JavaScript, Math · Jan 12, 2021

  • Number is primitive

    Checks if the passed value is primitive or not.

    JavaScript, Type · Oct 22, 2020

  • Same-origin URLs

    Checks if two URLs are on the same origin.

    JavaScript, Browser · Apr 22, 2021

  • Check if sessionStorage is enabled

    Checks if sessionStorage is enabled.

    JavaScript, Browser · Dec 31, 2020

  • Value is string

    Checks if the given argument is a string. Only works for string primitives.

    JavaScript, Type · Oct 20, 2020

  • Pad number

    Pads a given number to the specified length.

    JavaScript, String · Oct 3, 2020

  • Round number to given precision

    Rounds a number to a specified amount of digits.

    JavaScript, Math · Oct 22, 2020

  • Time taken by function

    Measures the time it takes for a function to execute.

    JavaScript, Function · Oct 22, 2020

  • Array union

    Returns every element that exists in any of the two arrays at least once.

    JavaScript, Array · Oct 22, 2020

  • Validate number

    Checks if the given value is a number.

    JavaScript, Math · Oct 22, 2020

  • Apply function when condition is met

    Returns a function that takes one argument and runs a callback if it's truthy or returns it if falsy.

    JavaScript, Function · Oct 22, 2020

  • Check if bottom of page is visible

    Checks if the bottom of the page is visible.

    JavaScript, Browser · Oct 22, 2020

  • Clamp number

    Clamps num within the inclusive range specified by the boundary values a and b.

    JavaScript, Math · Oct 22, 2020

  • Copy sign to number

    Returns the absolute value of the first number, but the sign of the second.

    JavaScript, Math · Oct 7, 2020

  • Number in range

    Checks if the given number falls within the given range.

    JavaScript, Math · Nov 1, 2020