0

What is the nature of the data structure used to store the name of a function in JavaScript?

In other words, where is the string "Foo" (i.e. the name of the function Foo) stored when this code is evaluated?

function Foo() {}

Also, do anonymous functions have a hidden name?

1 Answer 1

1

where is the string "Foo" (i.e. the name of the function Foo) stored

In the global scope.

You can avoid this by using a self invoking anonymous function :

(function() {
    alert('Hello World');
})();

, or by associating a var to a function within a local scope :

function myBigFunction() {
var myfunction = function foo(){alert('Hello World');};
}

No hidden name.

Sign up to request clarification or add additional context in comments.

2 Comments

Okay, I know this. I am considering whether there is something akin to an execution context (i.e. a data structure internal to the interpreter) that holds function metadata?
@Ben if there is it is not part of the accessible api, afaik, and would be dependent to the particular interpreter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.