Learn JavaScript #1 | Introduction

JosephDelgadillo
58 followers
491 Video Views·Aug 16, 2024
Get The Learn to Code Course Bundle! https://josephdelgadillo.com/product/learn-to-code-course-bundle/
JavaScript is an extremely valuable scripting language that allows you to create functions, classes, event handlers, etc. within a website. In this tutorial video, we will cover how to create JavaScript files in your web project, inline js, and your first program!
Learn more about my courses at https://josephdelgadillo.com
Alright, we are going to jump right into JavaScript at this point, so
JavaScript is really fun because it is a scripting language which is I guess like a
programming language. There are differences between the two, but you can
create functions, and classes, and you know there's event handlers and stuff
like that. So, that is what we're going to be doing in this video. So I'm going to
right click on my web course root directory here, and I'm going to create a
new directory called js for my JavaScript files. And in here I'm going
to create a JavaScript file and I'm going to call it main, and it's going to
automatically give it the extension .js. So, this is what we're going to be
writing our JavaScript in, and you can include it much like you include a style
sheet. At the top of the page here just include your script instead, and actually
that's wrong so I'm going to show you guys the right way. It's generally
recommended to include your script at the bottom of the body. The script has a
source, or SRC attribute, and this is the location of the JavaScript file. So in
this case it's in the JavaScript directory main.js. This is not self
closing. So, there we go we've included our script, but we're not
going to use it yet, actually. What I'm going to do in this video is we're just
going to do a bit of inline JavaScript, and how you do that is you're going to
define your script wherever you want it activate, and then we're going to type
document.write and I'm going to write "hello world" and I'm going to save it.
And document means the actual document, and write is a method of that. So, just to
get you guys writing hello world, I'm going to save this, I'm going to refresh,
and up here where I put that script you'll see it says hello world.
And so that's how to write to the document in JavaScript. Now if you guys
have no programming background, what this basically means is document is an
object, and when you write an object each object has methods and variables that
you can print out. So, the method here that we're calling is write, and a method
typically has brackets here and you can supply arguments to it. So an argument in
this case is "hello world." It's a string, it's quoted in text, and we're going to
be getting into more programming concepts as we go along here. But, for
right now, all you guys need to write is document.write and then inside these
regular brackets here you type "hello world" within quotations. Quotations tells
it that it's a string. If we remove the quotations altogether, we're going to get
that underline there, and when we write this or when we refresh the JavaScript
is going to output down here in the console and it's going to say missing
that after argument list. And the reason is because we don't have a comma here
and we normally would if these were variables, which they're not quoted so
the compiler, or interpreter, is thinking that we're passing it two values
and each one of those values is its own variable, and we're going to be
discussing variables as well. For right now, you guys can write document.write
"hello world" and when you save it and refresh it's going to print hello
world onto the screen for you, and that is the very first step into JavaScript.
Now in the next video we're going to be learning about a lot of more basic
things. We're going to learn about variables, and integers, and stuff like
that, and then we're going to move on to be able to create functions and
objects of our own that we can interact with. And, we're going to learn how all
this relates to the content that's on the page.
