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

  • Quotient and module of division

    Returns an array consisting of the quotient and remainder of the given numbers.

    JavaScript, Math · Oct 7, 2020

  • Factorial of number

    Calculates the factorial of a number.

    JavaScript, Math · Dec 28, 2020

  • HSB to RGB

    Converts a HSB color tuple to RGB format.

    JavaScript, Math · Sep 18, 2020

  • HSL to RGB

    Converts a HSL color tuple to RGB format.

    JavaScript, Math · Oct 4, 2020

  • Midpoint

    Calculates the midpoint between two pairs of (x,y) points.

    JavaScript, Math · Oct 21, 2020

  • How can I check if a number is even or odd using JavaScript?

    Check if a number is even or odd using JavaScript using the modulo operator or bitwise AND operator.

    JavaScript, Math · Oct 6, 2023

  • What is the difference between prefix and postfix operators?

    While both the prefix and postfix operators increment a value, the resulting value of the expression is very different.

    JavaScript, Math · Oct 31, 2021

  • RGB to HSB

    Converts a RGB color tuple to HSB format.

    JavaScript, Math · Oct 22, 2020

  • RGB to HSL

    Converts a RGB color tuple to HSL format.

    JavaScript, Math · Oct 4, 2020

  • Format number

    Formats a number using the local number format order.

    JavaScript, String · Oct 22, 2020

  • Number to decimal mark

    Converts a number to a decimal mark formatted string.

    JavaScript, Math · Oct 22, 2020

  • Distance between two points

    Calculates the distance between two points.

    JavaScript, Math · Dec 28, 2020

  • Number has decimal digits

    Checks if a number has any decimals digits

    JavaScript, Math · May 13, 2022

  • Number is prime

    Checks if the provided integer is a prime number.

    JavaScript, Math · Jan 12, 2021

  • Pad number

    Pads a given number to the specified length.

    JavaScript, String · Oct 3, 2020