DEV Community

Discussion on: Write a function that shows off something unique or interesting about the language you're using

Collapse
 
dwd profile image
Dave Cridland

Javascript... Yes, Javascript is a barrel of pure quirk. Just pick variable scope. As if it wasn't bad enough that hoisting exists, the bizarre way scopes work allows you to write some truly awe-inspiring hackery, like this Fibonacci function:


function fib(n) {
  if (n) {
    a = 1;
    b = 0;
    c = n + 1;
  }
  if (c === 1) {
    return a + b;
  }
  c = c - 1;
  let d = a + b;
  b = a;
  a = d;
  return fib();
}