Wilfred Almeida
Wilfred Almeida

Reputation: 651

How to access local function variable in chrome console?

var MyFunc =
  MyFunc ||
  (function (u, p) {....})

If this code is in a file named abc.js and there multiple JS files for the website, how do I print the variable u in chrome's console?

I tried console.log(u), console.log(MyFunc.u) both didn't work.

Upvotes: 1

Views: 1580

Answers (1)

Apoorva Chikara
Apoorva Chikara

Reputation: 8773

If I understand that correctly, you can do this:

var MyFunc =
  MyFunc ||
  (function (u, p) {
      console.log(u);
      console.log(p);
   }
  );

MyFunc(1, 2);

When you run the above code, it will assign anonymous function to MyFunc and then you need to call that function definition by passing the parameters.

Upvotes: 2

Related Questions