In short: I would recommend you to use const
. Why?
(In the following examples, assume we are in a browser environment.)
Function declarations/statements
They are hoisted and become properties of the global object.
fn(); // No error
function fn() {}
console.log('fn' in window); // true
Function expressions with var
They are not hoisted, but a variable declared in the global scope always becomes a property of the global object.
fn(); // TypeError
var fn = function () {};
console.log('fn' in window); // true
Function expressions with let
They are not hoisted, they do not become properties of the global object, but you can assign another value to your variable. Since JavaScript is loosely typed, your function could be replaced by a string, a number, or anything else.
fn(); // ReferenceError
let fn = () => {};
console.log('fn' in window); // false
fn = 'Foo'; // No error
Function expressions with const
They are not hoisted, they do not become properties of the global object and you cannot change them through re-assignment. Indeed, a constant cannot be redeclared.
fn(); // ReferenceError
const fn = () => {};
console.log('fn' in window); // false
fn = 'Foo'; // TypeError