#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
0:04 at how to run JavaScript.
0:05 And I will show you three methods you can do it.
0:07 And the first method is to just run it in a browser.
0:09 So let's first write out Hello World
0:12 and to make a file called hello.js.
0:16 And I'm going to write small function
0:18 and we will deal with language syntax starting
0:21 the next video. Just bare with me.
0:26 And we're going to return a string, 'Hello '' + name.
0:35 And to call this lets log a message to the console.
0:39 So I'm going to do a console.log, which would
0:42 be the equivalent of pythons print.
0:46 And I'm going to call the function passing in a name.
0:51 So we have a script, saved to hello.js
0:56 and how do we run this in a browser?
0:59 Well we can write a little bit of html.
1:03 So here's a simple html5 template
1:07 and the script tag allows you to import JavaScript
1:11 as well as just write it inside script tags.
1:15 So here I imported my script hello.js
1:19 as living in the same directory.
1:22 And here I can call it, so I don't need this for now.
1:29 And what I now can do, is open this index file
1:32 in the browser and nothing happens.
1:35 So what you first want to do is to click inspect
1:39 and we'll open the Chrome dev tools
1:42 and you head over to console, end of string must print it.
1:45 And here you have this function now available
1:49 so here's the source code.
1:55 You can call it with and that is
1:57 to the finer variable, we will see that in the next
2:01 video and now I can call that function with another name.
2:06 That's nice. Now to complete. And there you go.
2:09 So here you have the console in the Chrome browser
2:12 you can imbed your script in Index@html and run it
2:16 interactively. The second way to run it is to use
2:19 server side JavaScript or Node.js but you would have
2:23 to install Node and then you can run it at the terminal.
2:27 So you would come down to Node.js, download the starter
2:32 of yours and install it from the package.
2:37 I've already done that so then the work flow would be
2:41 you don't need this HTML, you can write your function
2:45 you can write the console log here, go to background
2:52 and now I can just run it, node hello.js.
2:54 So if you like to work with a terminal then that's a
2:57 second way you can run JavaScript.
3:01 Install Node.js write your code and run it from the
3:04 command line.
3:06 A third way is to use an IDE. So here I have my VS Code
3:10 editor open, I can put in the JavaScript I just wrote
3:16 and by default there is not a run code option here
3:21 so you would want to install VS Code runner
3:27 you can get that from the Visual Studio marketplace
3:31 install it, open it in visual studio code, you can install
3:36 it here, install, now it's installed and here I've got
3:44 a new option under my right click called runcode.
3:49 Here it opened a pain running the code and the output.
3:53 So that would be the third way to run JavaScript
3:57 using IDE and probably with an extension
4:02 and this is VS code.
4:04 I've actually just discovered this IDE. You will still
4:07 see me use VIM throughout this lesson though but yeah
4:10 I know a lot of you use IDE so this is worth exploring
4:13 and the process will probably be very similar for your IDE
4:17 of choice. In the next video we are going to dive into
4:20 the language syntax.