Declaring a function with let?

I was wondering if there’s ever a context where a function is declared using let instead of const. My first guess is that’s not possible/necessary but I’m curious.

The idea of let is that its value can be altered, and even its type. Consider the following frivolous example…

const multifunction = () => {
  let x = 50;
  do {
    let func = Math.random() < 0.5 ? n => n / 10 : n => n * 10;
    x = func (x);
  } while (x > 1);


Because our function is declared with let we can swap out its body at will. Above the function func alternates randomly between two functions.

Try it…


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.