0

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!

3
  • Where did you see undefined? It logs string to the console for me. You say it returns undefined, which, if you mean what you say, is correct. console.log doesn't return anything (which mean that it returns undefined by default). Commented Oct 7, 2017 at 5:28
  • Yeah, I can only imagine that it shows you the return value of the last expression/statement, which, as I said, is undefined for console.log, so that's correct. Commented Oct 7, 2017 at 5:36
  • Hi @Felix, it appears when I click on Display rather than Run Code in the scratchpad window (until the 47 release isn't nested on the developer tools). Would you like a screenshot? I noticed you mentioned the console rather than the scratchpad, yet I got exactly the same result on both environments. I'm going to try on a newer Firefox release however. Thanks for your help! Commented Oct 7, 2017 at 5:39

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.