Mathematical tricks of Javascript

factorial formula

Factorial (n!):

The factorial of n is denoted by n! and calculated by the product of integer numbers from 1 to n.

For n>0,

n! = 1×2×3×4×…×n

For n=0,

0! = 1

Factorial definition formula


1! = 1

2! = 1×2 = 2

3! = 1×2×3 = 6

4! = 1×2×3×4 = 24

Recursive factorial formula

n! = n×(n-1)!


4! = 4×(4–1)! = 4×3! = 4×6 = 24

factorial 5! =?

Let’s solve the in Javascript

Fibonacci Series:

The Fibonacci numbers are generated by setting F0 = 0, F1 = 1, and then using the recursive formula
Fn = Fn-1 + Fn-2
to get the rest. Thus the sequence begins: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, … This sequence of Fibonacci numbers arises all over mathematics and also in nature.

Prime Number:

A prime number is a natural number greater than 1 that is not a product of two smaller natural numbers. A natural number greater than 1 that is not prime is called a composite number. For example, 5 is prime because the only ways of writing it as a product, 1 × 5 or 5 × 1, involve 5 itself.

Truthy Vs Falsy:

There are six types of primitive data has in Javascript. Boolean is one of the data types of Javascript. Boolean data has a base true or false value.

The following values are always Falsy:

  • false
  • 0 (zero)
  • '' or "" (empty string)
  • null
  • undefined
  • NaN

Everything else is truthy. That includes:

  • '0' (a string containing a single zero)
  • 'false' (a string containing the text “false”)
  • [] (an empty array)
  • {} (an empty object)
  • function(){} (an “empty” function)

A single value can therefore be used within conditions

Double equal Vs Triple equal:

Double (==) check only value and Triple equal(===) check type and value. Here var num1 is 2 which is a number and var num2 is also 2 but which is a string. when checking this using double equal we get output true cause It checks only value but when checking this using triple equal we get output false cause num1 is number, num2 is a string.num1 and num2 are different types of data.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store