Why does Snippets Console display 'undefined' after displaying what's in console.log?

4,079 views
Skip to first unread message

Tony Henrich

unread,
Nov 6, 2014, 1:33:03 PM11/6/14
to google-chrome-...@googlegroups.com
Why does Snippets Console display 'undefined' after displaying what's in console.log? My snippet has one line: console.log('test');. When I run it, it displays 'test' and 'undefined in the second line. Why? I am using latest Chrome Canary and regular Chrome.

PhistucK

unread,
Nov 6, 2014, 1:48:11 PM11/6/14
to Google Chrome Developer Tools
Using Chrome 38, typing console.log("test") directly in the console does the same.
The reason for that is that the console prints the value that is returned by the last statement.
console.log(...) returns undefined (well, returns nothing, void, for that matter), so you get undefined.
If the last statement returns something else (or has a value), that would be displayed.

console.log("test"); // Prints test.
"test"; // Prints test as well.

var test = "test";
console.log("test"); // Prints test.
test; // Prints test as well.



Note that this only happens in the console, not in JavaScript run as part of a page.


PhistucK

On Thu, Nov 6, 2014 at 8:33 PM, Tony Henrich <thenri...@gmail.com> wrote:
Why does Snippets Console display 'undefined' after displaying what's in console.log? My snippet has one line: console.log('test');. When I run it, it displays 'test' and 'undefined in the second line. Why? I am using latest Chrome Canary and regular Chrome.

--
You received this message because you are subscribed to the Google Groups "Google Chrome Developer Tools" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-chrome-develo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-chrome-developer-tools/b21d1f1c-210a-4bf1-b3a5-ceb8c0c9ae9b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages