This course has been updated! We now recommend you take the JavaScript: The Hard Parts, v2 course.

Check out a free preview of the full JavaScript: The Hard Parts course:
The "Browser API Q&A, Part 2" Lesson is part of the full, JavaScript: The Hard Parts course featured in this preview video. Here's what you'd learn in this lesson:

Will takes a question from a student about running console.log() within setTimeout.

Get Unlimited Access Now

Transcript from the "Browser API Q&A, Part 2" Lesson

>> Speaker 1: So I have a question about using the time out function console log.
>> Will Sentance: When you were asked to setTimeout on a console log, some of you passed the call to the console log built in function straight in, instead of a function declaration. When I write this, when I write console.log('hello'), is that storing a function?

>> Speaker 3: No.
>> Will Sentance: Is that declaring a function? No, right? It's saying do this immediately, right? It's saying, run this. So if I pass in a thing being called into that place in which I should be passing a function definition. So I should be passing a function definition in the setTimeout, what's gonna be passed down here?

[00:00:46] If I pass, though, a running of a function, it's just gonna do it. And now that's gonna evaluate to something, which will then be passed in here, but that's no use to us. So if I pass an immediate invocation, immediately running the function into my call to setTimeout, then yeah, I'm gonna do it immediately.

[00:01:05] So it's gonna happen first. Does that make sense, everyone? If I were to, instead of defining printHello as wrapping a printing of console log Hello, console logging Hello. But instead just pass in console log Hello, well, it's gonna do it immediately before I even start doing setTimeout. It's got ahead of its parameter being done.

[00:01:25] If it says invoke it, it's gonna do that before I even start doing setTimeout. So it's gonna be immediate. Does that make sense as to why that happened? Okay, because that happened to Lindsay as well.