The first scareMe function overwrites its own behavior when called, creating another scareMe function in it, which overwrites the one in the upper scope, so the definition of the original scareMe changes, I see that this approach was used if you want to do it the first time in the application and want to change its behavior immediately after setting it up.
If you have identified:
var scareMe = function(){ console.log("Boo!"); var scareMe = function(){
Also one practical implementation of a one-time installation:
var scareMe = function(){ console.log("Boo!");
In the second case, you create a new function called scareMe , whose scope is only inside the function, it is not overwritten.
Try this for example:
function scareMe(){ console.log("Boo!"); function scareMe(){ console.log("Double bool!"); } scareMe();
source share