WEBVTT

1
00:00:00.400 --> 00:00:02.500
Let's dive into the world of JavaScript

2
00:00:02.530 --> 00:00:05.860
by starting a fun project
in a new and empty folder.

3
00:00:05.890 --> 00:00:09.940
Open your preferred IDE
such as Visual Studio Code.

4
00:00:09.970 --> 00:00:14.980
I have opened WebStorm because that's
my favorite IDE and let's create a new

5
00:00:15.010 --> 00:00:21.860
file name play.js
the name is entirely up to you.

6
00:00:21.890 --> 00:00:23.100
Before we start coding,

7
00:00:23.130 --> 00:00:27.620
let's review some core language features
including variables and functions.

8
00:00:27.650 --> 00:00:31.340
For now, it is assumed that you have
a basic understanding of variables,

9
00:00:31.370 --> 00:00:35.540
functions, if statements and loops as
these are essential components

10
00:00:35.570 --> 00:00:40.460
of JavaScript programming whether you're
using it in the browser or on the server.

11
00:00:40.490 --> 00:00:43.980
To declare a variable in JavaScript we use

12
00:00:44.010 --> 00:00:47.620
var keyword and then
the name of the variable.

13
00:00:47.650 --> 00:00:52.900
So let's create a variable called name
and let's give it the value of Nata.

14
00:00:52.930 --> 00:00:57.100
Now this name can be used
to output variable's value.

15
00:00:57.130 --> 00:01:00.380
So if I do this, save this.

16
00:01:00.410 --> 00:01:07.050
And then try to run this,
I will see the output of Nata.

17
00:01:07.080 --> 00:01:12.290
We can also create variables of different
data types such as numbers and booleans.

18
00:01:12.320 --> 00:01:20.980
For example, my age is 26 and I have

19
00:01:21.010 --> 00:01:24.930
some hobbies. So, I can set this to true.

20
00:01:24.960 --> 00:01:34.080
If I were to output the values
of these variables, we are going to

21
00:01:34.110 --> 00:01:36.465
see all of these console log.

22
00:01:36.665 --> 00:01:40.850
Functions are
declared using function keyword followed

23
00:01:40.880 --> 00:01:46.440
by the function name such as function

24
00:01:46.560 --> 00:01:51.260
who is user and we can pass it the name

25
00:01:51.290 --> 00:01:57.660
and we can pass it an age
and it can return a certain string.

26
00:01:57.690 --> 00:02:07.210
Let's say, name is - name and age is - age.

27
00:02:07.240 --> 00:02:14.380
In this example, the function of who is
user accepts two arguments: name and age,

28
00:02:14.410 --> 00:02:19.660
and it returns a string with the
description of who is the user.

29
00:02:19.690 --> 00:02:24.610
To call a function, we simply use its name
followed by parentheses

30
00:02:24.640 --> 00:02:30.300
and then we pass it the arguments that it
needs so that it executes correctly.

31
00:02:30.330 --> 00:02:32.610
So here we can use the variables that we

32
00:02:32.640 --> 00:02:37.100
created above and we can console
log the value of this function.

33
00:02:37.130 --> 00:02:45.500
So if we were to rerun this again,
we would see name is nata and age is 26.

34
00:02:45.530 --> 00:02:47.610
It's important to note that variables

35
00:02:47.640 --> 00:02:51.860
declared within a function are local
and cannot be accessed outside

36
00:02:51.890 --> 00:02:56.220
of the function due to the concept
of scoping in JavaScript.

37
00:02:56.250 --> 00:03:00.140
However, we can access global
variables within a function.

38
00:03:00.170 --> 00:03:04.800
So if we were to create a variable here

39
00:03:05.960 --> 00:03:08.740
let's say we call this

40
00:03:08.770 --> 00:03:14.540
name age combination and we were to

41
00:03:14.570 --> 00:03:17.260
do this, if we tried to output

42
00:03:17.290 --> 00:03:19.080
it here -

43
00:03:22.400 --> 00:03:24.000
our editor will already be

44
00:03:24.000 --> 00:03:25.900
telling us that we don't
have access to this.

45
00:03:25.930 --> 00:03:28.700
However, let's run this and see what

46
00:03:28.730 --> 00:03:35.180
happens and we get an error saying
name age combination is not defined.

47
00:03:35.210 --> 00:03:37.080
However, if we were to do the

48
00:03:37.110 --> 00:03:46.800
same here and we try to console log
name age combination here

49
00:03:47.000 --> 00:03:50.040
if we were to run this

50
00:03:51.760 --> 00:03:52.610
we would see

51
00:03:52.640 --> 00:03:56.460
the name age combination here
because this is a global variable.

52
00:03:56.480 --> 00:03:58.220
In conclusion, this is just a quick

53
00:03:58.240 --> 00:03:59.940
overview of the core features you should

54
00:03:59.970 --> 00:04:01.700
be aware of in JavaScript.

55
00:04:01.720 --> 00:04:05.060
Variables, functions, arguments,
and scoping are essential components

56
00:04:05.090 --> 00:04:07.780
of the language,
and mastering these concepts will lay

57
00:04:07.810 --> 00:04:12.100
a strong foundation for your future
JavaScript programming adventures.

58
00:04:12.130 --> 00:04:15.860
In the next lecture,
we'll delve into more exciting topics.

59
00:04:15.880 --> 00:04:16.840
See you in the next video.

