Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Console.log always returns undefined in Chrome [duplicate]

I just encountered this weird problem. I don't remember I have it before but it has been quite a while since last time I develop any Chrome stuff.

The picture below pretty much speaks it by itself:

enter image description here

Why does Chrome console constantly return undefined for console.log command? Any console.log used in js scripts also return the same.


Update

console.log.toString() returns "function log() { [native code] }"

like image 235
Anthony Avatar asked Oct 15 '18 12:10

Anthony


People also ask

Why does Chrome console say undefined?

If a function does not use a return statement or an empty return statement with no value, JavaScript automatically returns undefined. That means that in JavaScript every function returns something, at least undefined.

Why is my console log returning undefined?

This is because console. log() does not return a value (i.e. returns undefined). The result of whatever you entered to the console is first printed to the console, then a bit later the message from console. log reaches the console and is printed as well.

What does undefined in console mean?

The undefined property indicates that a variable has not been assigned a value, or not declared at all.

Does console log return anything?

Return value: It returns the value of the parameter given. JavaScript codes to show the working of this function: Passing a number as an argument: If the number is passed to the function console.log() then the function will display it.


1 Answers

Are you filtering the messages by chance? Look in the upper right corner of the console to see if it says “1 hidden”.

Screenshot of devtools, "Hide all / 6 hidden" emphasized

like image 72
Josh Lee Avatar answered Sep 20 '22 22:09

Josh Lee