why inspect tool display extra undefined 1

why inspect tool display extra undefined

102

If you're running console.log() from a JS file, this undefined line should not be appended.

If you're running console.log() from the console itself, it makes sense. This is why: In the console you can type a name of a variable (for example try typing window) and it prints info about it. When you run any void function (like console.log) from the console, it also prints out info about the return value, undefined in this case.

I tested both cases on my Chrome (Mac ver 23.0.1271.101) and indeed I see the undefined line when I run it inside the console. This undefined also appears when I write this line in the console: var bla = "sdfdfs"

Here is what the above code is Doing:
1. It’s creating a function called “log” that takes in a parameter called “message”.
2. It’s creating a variable called “console” and assigning it to the global object’s “console” property.
3. It’s creating a variable called “oldLog” and assigning it to the “console” object’s “log” property.
4. It’s assigning the “log” function to the “console” object’s “log” property.
5. It’s returning the “console” object.

So, when you call “console.log”, you’re actually calling the “log” function.

The “log” function is doing the following:
1. It’s calling the “oldLog” function and passing in the “message” parameter.
2. It’s returning the “console” object.

So, when you call “console.log”, you’re actually calling the “log” function, which is calling the “oldLog” function, which is printing out the “message” parameter.

The “log” function is also returning the “console” object, which is why you see “undefined” in the console.

Similar Posts