#100DaysOfWeb in Python Transcripts
Chapter: Days 25-28: JavaScript Introduction
Lecture: How to run JS in your browser / terminal / IDE
Login or
purchase this course
to watch this video and the rest of the course contents.
0:01
First let's actually look at how to run JavaScript. And I will show you three methods you can do it.
0:08
And the first method is to just run it in a browser. So let's first write out Hello World and to make a file called hello.js.
0:17
And I'm going to write small function and we will deal with language syntax starting the next video. Just bare with me.
0:27
And we're going to return a string, 'Hello '' + name. And to call this lets log a message to the console. So I'm going to do a console.log, which would
0:43
be the equivalent of Pythons print. And I'm going to call the function passing in a name. So we have a script, saved to hello.js
0:57
and how do we run this in a browser? Well we can write a little bit of HTML. So here's a simple HTML5 template
1:08
and the script tag allows you to import JavaScript as well as just write it inside script tags. So here I imported my script hello.js
1:20
as living in the same directory. And here I can call it, so I don't need this for now. And what I now can do, is open this index file
1:33
in the browser and nothing happens. So what you first want to do is to click inspect and we'll open the Chrome dev tools
1:43
and you head over to console, end of string must print it. And here you have this function now available so here's the source code.
1:56
You can call it with and that is to the finer variable, we will see that in the next video and now I can call that function with another name.
2:07
That's nice. Now to complete. And there you go. So here you have the console in the Chrome browser you can imbed your script in Index@HTML and run it
2:17
interactively. The second way to run it is to use server side JavaScript or Node.js but you would have
2:24
to install Node and then you can run it at the terminal. So you would come down to Node.js, download the starter
2:33
of yours and install it from the package. I've already done that so then the work flow would be you don't need this HTML, you can write your function
2:46
you can write the console log here, go to background and now I can just run it, node hello.js. So if you like to work with a terminal then that's a
2:58
second way you can run JavaScript. Install Node.js write your code and run it from the command line.
3:07
A third way is to use an IDE. So here I have my VS Code editor open, I can put in the JavaScript I just wrote
3:17
and by default there is not a run code option here so you would want to install VS Code runner you can get that from the Visual Studio marketplace
3:32
install it, open it in Visual Studio Code, you can install it here, install, now it's installed and here I've got
3:45
a new option under my right click called runcode. Here it opened a pain running the code and the output.
3:54
So that would be the third way to run JavaScript using IDE and probably with an extension and this is VS Code.
4:05
I've actually just discovered this IDE. You will still see me use VIM throughout this lesson though but yeah
4:11
I know a lot of you use IDE so this is worth exploring and the process will probably be very similar for your IDE
4:18
of choice. In the next video we are going to dive into the language syntax.