DEV Community

Cover image for How to Calculate the Nth Fibonacci Number
Jon Randy 🎖️
Jon Randy 🎖️

Posted on

13 1 1 1

How to Calculate the Nth Fibonacci Number

Okay, lets dive straight into the code...

const fib = n =>
  Math.floor((((1 + 5**.5)/2)**n - ((1 - 5**.5)/2)**n)/5**.5)
Enter fullscreen mode Exit fullscreen mode

Explanation here.

Top comments (1)

This post blew up on DEV in 2020:

js visualized

🚀⚙️ JavaScript Visualized: the JavaScript Engine

As JavaScript devs, we usually don't have to deal with compilers ourselves. However, it's definitely good to know the basics of the JavaScript engine and see how it handles our human-friendly JS code, and turns it into something machines understand! 🥳

Happy coding!

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay