Why is a JavaScript call with a named assigned function not performed in JavaScript?

Below is probably a little pointless, but why does the first call below work while the second fails?

var foo = function bar() {
  console.log("Martini");
}

foo(); // works
bar(); // undefined; i.e. "Uncaught ReferenceError: bar is not defined"

How to do this with a region?

The initial newbie’s task: defining a function “parses” - but this is really valid syntax - and is there any context that makes sense to assign a designated anonymous function?

+4
source share
1 answer

A function declaration creates a variable with the same name as in the current scope.

( ) . ( ) .

+8

All Articles