Search code examples
javascriptlambdalocal-variablesgoogle-chrome-console

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.


Solution

  • 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.