[MUSIC]
>> Creating your first application.
Hey folks, this is Burke Holland, and in this video,
we're going to look at creating your first JavaScript application.
Specifically, we're going to be making a Node.js application.
Now, the first thing that we're going to need
to create a project is a file,
somewhere to put our code, and we can save that,
and we'll call it index.js,
but you can call it anything you like.
We have to save it somewhere.
We're going to want to put it in a folder.
Again, you can call this folder whatever you like.
Just like that, technically, we have a project.
Now, it doesn't do anything, but it is a project.
All a project is a folder with
some files or other folders that have files in it,
it just contains your code.
Now, let's make this project do something.
One of the things that you'll use frequently in
JavaScript is something called the console.log command.
Console.log simply allows you to
output a message to the console window.
The console window is a place
where all sorts of messages are output like,
errors, and logs, and any
messages that you want to write out from your code.
In the case of a Node.js application,
the console appears in the same place where you run your code,
which is from the terminal or the command line.
We can write "Hello World" out to the console and then
run this program by running node and then index.js,
and we see the message written out to the terminal.
Now, it's important to note that you can log
out any string, including,
by the way, emoji,
good to know, completely valid, you can do that.
Another thing to note here is that I'm using single quotes around
these texts that I want to write out with
console.log statement. Why am I doing that?
Well, I'm doing that because I need to tell
JavaScript that this is text.
If I remove the quotes,
then you can see we have errors.
That's because hello and
world are not valid commands in JavaScript,
and any text that's not inside of quotes,
JavaScript thinks you're trying to call a command.
To tell JavaScript, "No,
this is just text.
We have to put quotes around it."
Now in my case, I'm using single quotes,
but you can also use double-quotes.
JavaScript honestly doesn't care either way,
you can use whichever one you like.
Now, sometimes you want to log out
the value of something that you don't know ahead of time.
For instance, could be the value of
a variable or the return value of a function.
The program will know the value,
but you don't know the value.
What you can do with console.log is
use something called substitutions.
Perhaps we want to define a variable here,
and then we want to include the value of
that variable in the output message.
We can write console.log,
and then wherever we want to have
these variables or program values show up,
we can use this percent sign-s. Then we just pass in
the parameter comma after the text into the console.log function.
You can have as many of these as you like,
and they will appear in the order that you pass
the parameters to the console.log function.
Now, we've seen single-quotes,
and we've seen double-quotes,
but there's actually a third type of string in JavaScript,
seriously, and it's called the template literal.
Template literals are formed by using the backtick.
Now, you can put strings inside
of template literals inside of backticks,
but it also allows you to put programmatic values in your strings.
To do that, you're going to use the dollar sign and then brackets,
and then you put whatever variable you want the value of
or function or whatever inside of that space,
and that will be written into the string.
Now, this is better than substitutions,
because it's easier to read as
a programmer and see where in the string
your values are when you're using
template literals than it is when you're using substitutions,
which can be a little bit harder to read.
In summary, JavaScript application is
just a folder with some files or
other folders in it that contain your code.
The console.log is your best friend
as a JavaScript developer because
it allows you to write messages from your code out to the console,
and you can use single quotes, double quotes,
or you can use the backtick,
which is the template literal in JavaScript,
which allows you to interpolate or combine
text and programmatic values like variables.