ankakusu
ankakusu

Reputation: 1828

How to define a javascript function from Chromium Console

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?

Upvotes: 4

Views: 20451

Answers (3)

Valter Ekholm
Valter Ekholm

Reputation: 335

You can also write

document.myFunc = function(){alert("Hello");}

Call it with

document.myFunc()

But I'm not an expert

Upvotes: 2

Prince Kumar
Prince Kumar

Reputation: 55

You can try this:

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

fun(5,6); // calling

Upvotes: 1

mikach
mikach

Reputation: 2427

function is reserved word in javascript.

Try this

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

instead of

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

Upvotes: 5

Related Questions