Let's dive into the world of JavaScript
by starting a fun project in a new and empty folder.
Open your preferred IDE such as Visual Studio Code.
I have opened WebStorm because that's my favorite IDE and let's create a new
file name play.js the name is entirely up to you.
Before we start coding,
let's review some core language features including variables and functions.
For now, it is assumed that you have a basic understanding of variables,
functions, if statements and loops as these are essential components
of JavaScript programming whether you're using it in the browser or on the server.
To declare a variable in JavaScript we use
var keyword and then the name of the variable.
So let's create a variable called name and let's give it the value of Nata.
Now this name can be used to output variable's value.
So if I do this, save this.
And then try to run this, I will see the output of Nata.
We can also create variables of different data types such as numbers and booleans.
For example, my age is 26 and I have
some hobbies. So, I can set this to true.
If I were to output the values of these variables, we are going to
see all of these console log.
Functions are declared using function keyword followed
by the function name such as function
who is user and we can pass it the name
and we can pass it an age and it can return a certain string.
Let's say, name is - name and age is - age.
In this example, the function of who is user accepts two arguments: name and age,
and it returns a string with the description of who is the user.
To call a function, we simply use its name followed by parentheses
and then we pass it the arguments that it needs so that it executes correctly.
So here we can use the variables that we
created above and we can console log the value of this function.
So if we were to rerun this again, we would see name is nata and age is 26.
It's important to note that variables
declared within a function are local and cannot be accessed outside
of the function due to the concept of scoping in JavaScript.
However, we can access global variables within a function.
So if we were to create a variable here
let's say we call this
name age combination and we were to
do this, if we tried to output
it here -
our editor will already be
telling us that we don't have access to this.
However, let's run this and see what
happens and we get an error saying name age combination is not defined.
However, if we were to do the
same here and we try to console log name age combination here
if we were to run this
we would see
the name age combination here because this is a global variable.
In conclusion, this is just a quick
overview of the core features you should
be aware of in JavaScript.
Variables, functions, arguments, and scoping are essential components
of the language, and mastering these concepts will lay
a strong foundation for your future JavaScript programming adventures.
In the next lecture, we'll delve into more exciting topics.
See you in the next video.