yucj
yucj

Reputation: 47

Why console.trace() result end at an "anonymous function"? What is that function?

If I run the code in the Javascript Console of an browser such as Chrome:

function foo() {
  function bar() {
    console.trace();
   }
   bar();
}
foo();

The result will be:

bar
foo
(anonymous function)

The console.trace() may trace to 'global scope' at the end. I know the global in the browser is the window object. But what is the specific function that (anonymous function) points to in the result?

Upvotes: 1

Views: 858

Answers (1)

Thalaivar
Thalaivar

Reputation: 23642

Its expecting an anonymous function as argument.

function Vinoth(){console.log("Vinoth")}
undefined

console.trace(Vinoth());
VM129:1 Vinoth

More info on this link: https://github.com/DeveloperToolsWG/console-object/blob/master/api.md#consoletraceobject--object-

Upvotes: 1

Related Questions