Running Code in the JS Console | Class 6 | The Modern Javascript Bootcamp Course (2023)
Caption:
Before we go any further, I want to stop and talk about where I'll be writing my code, at least for
this section in general.
Throughout the rest of the course, we write our code in a JavaScript file, a standalone file.
It could be 100 lines, it could be ten lines, it could be 10,000 lines.
We write the code and we run the code afterwards or separately.
For now, we're going to run our code in a more immediate way.
We're going to use the JavaScript console in Chrome.
So definitely, definitely recommend you install Chrome if you don't have it.
Now, other browsers have a console as well and you can use that.
But if you want to be on the same page as me, I would use the chrome console.
So here I have chrome open.
You could be on any web page.
It doesn't matter and I'm going to pull up the console.
So we have a couple of different options.
I like to use a shortcut, but first, if you go to view developer and JavaScript console right there,
you can click that.
Also take note of that shortcut on a mac.
It is command option J.
And it takes a moment.
Here is my console.
Notice there's different tabs.
If this is all new to you, we'll be working in the console tab so I can type code right away.
This is not valid code.
I get an error message but see this flow.
I type something, I hit enter and I get a result.
This is different than typing our code in a file, saving the file and then running the file.
That's the more traditional standard approach and there's a reason for that.
This is not a great place to write large applications.
Nothing you write is actually saved.
But when we're just experimenting, we're just starting out.
We want to talk about numbers, for example.
It's very easy for us to explore and see how things work without getting caught up in the workflow.
So just for this section, we'll be working in the console.
Usually the console is used for debugging, for trying things out.
Like I said, it's not a good place to actually write applications.
The other thing is that my console might look a little bit different than yours.
I have changed the colors to make it a little easier to see if you want to learn how to do that.
I have a YouTube video on it, but it's really not at all important.
It will work exactly the same as yours, even if you have the light theme.
A couple of other things I'll point out.
You can resize this, you can close it back down by exiting or using the same shortcut you use to open
it.
So for me it is command option J and now it's gone.
Also right here, if you click on this three dot more icon, I don't know what to call it.
You can change where the dock appears if you want it on the side, the right, the left, or you can
actually pop it out into its own window like this.
So now I have two windows, but this console is connected to this window here and that's pretty much
it.
Again, we're using this for this section to make our life easier.
It's too much setup.
It bogs us down to create new files and save them and open them up correctly every time we learn something
new early on.
But again, that's where we're going.
So that's the console command option J on a mac.
Next up, we'll actually start writing code.