How to define a javascript function from Chromium Console

13,227

Solution 1

function is reserved word in javascript.

Try this

var f = function() {
   console.log("Hello world");
};

instead of

var function = f(){
   console.log("Hello world");
};

Solution 2

You can try this:

function fun(a,b)
{
   console.log(a,b);
}

fun(5,6); // calling
Share:
13,227
ankakusu
Author by

ankakusu

Updated on July 09, 2022

Comments

  • ankakusu
    ankakusu almost 2 years

    I'm trying to define a Javascript function or a simple variable in Chromium Browser debugger console. After definition, when I cannot reach this function. What shall be the problem for it?

    Here are the variable and function definition that I write on the chromium console:

    var myvar;
    
    var f = function(){
       console.log("Hello world");
    };
    
    function f2(){
       console.log("Hello world");
    };
    

    By the way, I can reach the functions that I created at Mozilla Firefox Browser.

    What is the problem with Chromium Browser?