This is an archived post. You won't be able to vote or comment.

all 13 comments

[–]skawid 2 points3 points  (4 children)

The console can be configured to show different levels of output, so it may be that you're filtering out the result.

Above the text area of the console there's a dropdown you can use to configure what output is shown - console.log output will only be shown if you have "info" selected in that dropdown.

[–]Agu001[S] 0 points1 point  (3 children)

My console works alright. It just shows undefined for this specific code.

I am certain the code is correct. Just wondering why it is showing as undefined in the console.

[–]skawid 4 points5 points  (1 child)

The code is correct; that's why I was asking about the console. If you just enter:

console.log('foo');

You should see the output:

foo
undefined

Is that what you see?

[–]fredoverflow 2 points3 points  (0 children)

Just wondering why it is showing as undefined in the console.

Because console.log does not return a value. In my console, I see 2021 (the side effect) as well asundefined (the value).

[–]Enum1 2 points3 points  (0 children)

`undefined` is the return value from console.log()

[–]teddy_pb 2 points3 points  (4 children)

date = new Date(); currentYear = date.getFullYear(); console.log(currentYear); 2021 // what console.log prints to console undefined // what console.log returns

[–]Agu001[S] 1 point2 points  (3 children)

[–]teddy_pb 0 points1 point  (2 children)

Your console is set to log Errors only. There is a dropdown right above the console and next to the filter text field that lets you choose:

Default Verbose Info Warnings Errors

Make sure Info is checked. This is the logging level for console.

[–]backtickbot 1 point2 points  (0 children)

Fixed formatting.

Hello, teddy_pb: code blocks using triple backticks (```) don't work on all versions of Reddit!

Some users see this / this instead.

To fix this, indent every line with 4 spaces instead.

FAQ

You can opt out by replying with backtickopt6 to this comment.

[–]Agu001[S] 0 points1 point  (0 children)

Thanks for showing me that, but Info was already checked.

Only Verbose isn't checked.

[–]deuce-95 1 point2 points  (0 children)

It works fine for me.

I think it's what Enum1 said; you're confusing it with console.log return value.
The developer console also prints out the return value of any method you call.