In this video.
Let's talk about console dot log, the name that we have been mentioning from the beginning of this
course.
At this point, until this point, you all know what console log is, but it's time to learn more about
console log.
So let's get rocking.
Well, console log is a function.
One key word here is what is a function?
Even looking at a syntax, you see we have the square braces telling you is a function and it is used
to print any text to the console ranging from simple text variables, objects and arrays.
That's one key point about console.log.
The next point about console.log is that JavaScript console were built inside browsers and it is like
a command line interface that runs JavaScript on your JavaScript engine.
But behind the console is what we call read ever print and loop.
And in short, we call it repo.
All right.
Let's talk more about this report.
All right.
So let's say that we are trying to run a simple function inside the console.
So in the first place, it reads your input.
All right.
And then it evaluates it as JavaScript code and then it prints the results.
That's a work of the repo, right?
You sometimes hear the term repo being used to refer to any sort of programming shell that allows you
to enter code and see results immediately.
For instance, Node.js, Python and Ruby also provide similar repo shell.
All right, so let's get back to console.log and try something.
Let's open our console and do some simple calculations and let's see how it works behind the scene.
Let's try to type this.
Let's say one plus two.
When I hit enter, it will see that I have the result.
Three.
How this thing happened is because of what you call the repo built inside.
And if you are an object developer, you also have repo inside Node.js, meaning we are running JavaScript
on the server so the same syntax can be run inside Node.js or a Node.js environment.
So back to Visual Studio code.
Let's try to run a simple Node.js command, even though we haven't gone there yet, but for some demonstration
purposes, let's try it out.
But for this one before it works, unless we have not been installed.
But for now, don't worry if you don't have not been installed.
So I will go to terminal here and a new terminal and inside my terminal to be able to execute repo or
command inside my terminal.
I'm going to use node and now hit enter and can see that now I'm in the repo of node.js so the same
code I type one plus two when I hit enter, you see I have three.
This is what we call the repo and we have the same repo inside browser.
That is our console log.
But have a look.
You see that when you run this code as soon as it print the answer we have next line at that mean going
to loop through its looping but let's try to run a simple function and let's the difference here.
Let's try to run this function.
Remember, console.log is a function, right?
So let's say this function will say say hi.
Now have a look.
When I hit enter, two things are going to happen when I hit Enter.
First, we have the resort.
Say hello.
And on second line, we see what is called undefined.
Let me explain why this happened.
When executing a function in the console, for example, using the console log.
This one as we did well, it produces two lines of output.
One is the result and one is on define.
The first line is a result that we expect and indeed this is what we are expecting.
Okay.
The second line reads what is called undefined.
Why I got undefined here.
This is because the first line is the output that we instructed JavaScript to print, and the second
line is a result of evaluating our program.
The second line here you are trying to evaluate our program and in short our function called console.log.
So every JavaScript expression has a result, but some expressions such as the console.log function,
they all return an empty result called undefined.
So any expression that does not return an answer, the repo we give us as undefined.
All right, so that is it.
About the console, that log.