How to make Firefox's scratchpad behave as an online JS console?

943 Views Asked by At

The reason I want to make the browser scratchpad behave as an online console is because when I'm executing the following code in the Eloquent JS code sandbox:

var foo = typeof "abc";
console.log(foo);

Returns: string as expected. However, the exact same code in the Firefox (45 ESR) scratchpad returns: undefined. This behavior difference just make me wary about the gotten results on Firefox.

Trying to get the desired scratchpad behavior, and taking a look to the MDN article on this subject, it says:

You can write, run, and examine the results of code that interacts with the web page.

Basically suggesting that the executed code is tied to the page you are currently on (not completely sure about this). Based on this, further in the same article another section points out, that to run the code in the browser context rather than in the page context, the chrome and add-on debugging option should be enabled, which I did to no avail.

Any idea why this difference is arising? It has been successfully tested on Chrome 61, Safari 8, and 6, so I'm wondering if it might be a hidden feature/misconfiguration or ultimately a bug. Thanks a lot for all your help!

1

There are 1 best solutions below

0
On BEST ANSWER

console.log() dosen't return any value, thus it shows "undefined"

alert(console.log("anything")); //undefined

to show the output of console functions, open the console itself (not the scratchpad)

or remove console.log() from your code to show foo value, witch is "string"

summary: foo is string console.log(foo) is undefined