I know there are different ways of declaring a function in JavaScript. Specifically my doubt is with the "standard" way of declaring a function, let's say we have the next function:
function salute(name) {
let phrase = `Hello ${name}, nice to meet you`;
document.write(phrase + `<br/>`);
}
(I know document.write()
ain't a good practice, but I'm just using it to test code).
Now, it is possible to assign another function to salute
, e.g.:
salute = function(){
document.write(`This is a different function <br/>`);
}
Is the original salute
function declare like a var variable/object? I know one can redeclare a variable within the same scope if declared as var, e.g.:
var aVariable = 10;
var aVariable = 11;
But this doesn't work with let and const as explained here: Difference between var and let
Continuing with the original code, I realized I can redeclare salute
using var:
var salute = function(){
document.write(`This is a different function <br/>`);
}
But I can't do the same with let or const. This made me conclude that the "standard" way of declaring a function has an implicit var scope. Am I right?