Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,256 --> 00:00:06,400
All right well it's time that we discussed variables do you remember from middle school or Elementary School
2
00:00:06,656 --> 00:00:12,800
Play when you learn algebra you had to solve for what the value of x was X was some representation of a value well that's kind of
3
00:00:13,056 --> 00:00:19,200
I know what a variable is in programming it's a container that stores a value the variable behaves as if it
4
00:00:19,456 --> 00:00:25,600
Lower the value it contains there's two steps to creating a variable declaration and assignment to use a variable
5
00:00:25,856 --> 00:00:28,928
We have to first declare it we'll use the latch keyword
6
00:00:29,184 --> 00:00:30,720
Then a unique variable name
7
00:00:30,976 --> 00:00:31,744
Like X
8
00:00:32,256 --> 00:00:38,400
So what we have done is declaration each variable name needs to be unique if I
9
00:00:38,656 --> 00:00:41,216
If I were to declare another variable named X
10
00:00:41,728 --> 00:00:47,872
We would run into an error a syntax error identifier X has already been declared so your variable names
11
00:00:48,128 --> 00:00:52,992
Need to be unique I can declare two variables X and Y and they both have different names
12
00:00:53,248 --> 00:00:55,552
That is fine but they can't have the same name
13
00:00:56,064 --> 00:01:02,208
The next step to creating a variable is to assign it a value once you declare your variable you don't need to declare it again
14
00:01:02,464 --> 00:01:06,560
So I'm going to assign X to equal some number like 100
15
00:01:06,816 --> 00:01:11,424
We can use this variable X and it will behave as if it was the value
16
00:01:11,680 --> 00:01:16,032
Let me demonstrate it so if I was to cancel that log
17
00:01:16,544 --> 00:01:17,312
X
18
00:01:17,568 --> 00:01:20,384
Well then it's going to display 100
19
00:01:20,640 --> 00:01:23,200
If I were to change this value to 123
20
00:01:23,456 --> 00:01:26,272
Well ex is now 123
21
00:01:26,784 --> 00:01:31,392
You can do both declaration and assignment together that would look something like this
22
00:01:31,904 --> 00:01:34,976
Let x equal 123
23
00:01:35,488 --> 00:01:41,632
This is both declaration and assignment if you're creating a program and you know what your values should be you can ass
24
00:01:41,888 --> 00:01:42,912
Find them a value right away
25
00:01:43,168 --> 00:01:45,728
Sometimes you may want to accept some user input
26
00:01:46,240 --> 00:01:48,800
So then you might do assignment later in two steps
27
00:01:49,056 --> 00:01:51,104
It's really up to you how you write your program
28
00:01:51,616 --> 00:01:54,176
There's a few different data types in JavaScript
29
00:01:54,432 --> 00:02:00,576
The first is number like 123 let's create a descriptive name for our variable like age
30
00:02:00,832 --> 00:02:02,368
We will store at user's age
31
00:02:02,624 --> 00:02:08,768
According to my analytics in YouTube the average age of my viewers is 25 so let's say that
32
00:02:09,024 --> 00:02:10,304
At my age is 25
33
00:02:11,072 --> 00:02:13,888
Then if I was to console.log
34
00:02:14,400 --> 00:02:15,680
My age variable
35
00:02:16,192 --> 00:02:18,752
It would behave as if it were the number 25
36
00:02:19,264 --> 00:02:20,800
Let's create a few more variables
37
00:02:21,568 --> 00:02:24,128
Another example of a number could be price
38
00:02:24,384 --> 00:02:27,712
Let price equal 1099
39
00:02:27,968 --> 00:02:32,832
Maybe it's $10.99 or some other unit of currency of your choosing
40
00:02:33,344 --> 00:02:36,160
Then we will console.log price
41
00:02:36,672 --> 00:02:37,440
1099
42
00:02:38,208 --> 00:02:41,536
What about a GPA a grade point average
43
00:02:41,792 --> 00:02:47,680
My grade point average is a solid 2.1 it's not great but C's get degrees
44
00:02:48,192 --> 00:02:50,496
Console.log GPA
45
00:02:50,752 --> 00:02:51,776
2.1
46
00:02:52,288 --> 00:02:58,432
Using a template literal we can insert a variable using a placeholder within console.log I will
47
00:02:58,688 --> 00:02:59,456
Use back ticks
48
00:02:59,968 --> 00:03:00,992
Let's write a sentence
49
00:03:01,760 --> 00:03:06,880
You are then to insert a variable use dollar sign curly braces
50
00:03:07,648 --> 00:03:10,208
Play your variable name within the curly braces
51
00:03:10,464 --> 00:03:12,256
Then we can continue our sentence
52
00:03:12,512 --> 00:03:15,840
You are variable age years old
53
00:03:16,864 --> 00:03:19,680
Let's create another sentence using console.log
54
00:03:21,984 --> 00:03:25,568
The price is
55
00:03:25,824 --> 00:03:27,616
Dollar sign curly braces
56
00:03:28,384 --> 00:03:29,152
Price
57
00:03:30,176 --> 00:03:32,480
The price is $10.99
58
00:03:32,992 --> 00:03:36,576
I'm going to insert a dollar sign before our price
59
00:03:37,856 --> 00:03:39,392
And that looks better
60
00:03:39,648 --> 00:03:41,952
Feel free to choose some other unit of currency
61
00:03:42,208 --> 00:03:45,024
Okay let's add a sentence to display our GPA
62
00:03:45,280 --> 00:03:46,816
Console.log
63
00:03:48,608 --> 00:03:53,728
Your GPA is colon space
64
00:03:53,984 --> 00:03:59,360
We're inserting a variable we need dollar sign curly braces or displaying our GPA
65
00:04:00,384 --> 00:04:02,688
Your GPA is 2.1
66
00:04:02,944 --> 00:04:06,272
Now if you need to display the data type of a variable
67
00:04:06,528 --> 00:04:09,088
You can use console.log
68
00:04:09,856 --> 00:04:13,440
Then precede the variable with the type of keyword
69
00:04:13,952 --> 00:04:15,232
What is the type
70
00:04:15,488 --> 00:04:16,512
Of age
71
00:04:17,024 --> 00:04:18,559
Age is a number type
72
00:04:19,583 --> 00:04:21,887
Price is also a number type
73
00:04:22,143 --> 00:04:23,935
Same thing with GPA
74
00:04:24,191 --> 00:04:25,215
The real numbers
75
00:04:25,727 --> 00:04:27,263
Let's go over a different data type
76
00:04:29,567 --> 00:04:32,127
Let's go over strings
77
00:04:32,639 --> 00:04:35,199
A string is a series of characters
78
00:04:35,455 --> 00:04:38,015
Let's say we have a user's first name
79
00:04:39,807 --> 00:04:45,951
To create a string you can either use double quotes or single quotes personally I like double quotes
80
00:04:46,719 --> 00:04:49,279
Then you can type in some characters like first name
81
00:04:50,303 --> 00:04:54,143
Let's say my first name is bro feel free to pick your own first name
82
00:04:54,911 --> 00:04:58,751
I will display the type of my first name variable
83
00:04:59,007 --> 00:05:00,543
And it says it's a string
84
00:05:00,799 --> 00:05:02,079
A series of characters
85
00:05:03,103 --> 00:05:04,639
Then I will display my name
86
00:05:04,895 --> 00:05:06,175
Console.log
87
00:05:07,455 --> 00:05:08,735
First name
88
00:05:09,759 --> 00:05:11,039
Add it is bro
89
00:05:11,295 --> 00:05:13,343
Or whatever your first name is whatever you put here
90
00:05:14,367 --> 00:05:17,439
Let's include our variable within a template literal
91
00:05:19,231 --> 00:05:24,351
Your name is at a placeholder
92
00:05:24,863 --> 00:05:26,143
First name
93
00:05:26,655 --> 00:05:27,935
Your name is bro
94
00:05:28,703 --> 00:05:30,495
What are some other examples of a string
95
00:05:30,751 --> 00:05:32,799
Maybe somebody's favorite food
96
00:05:33,311 --> 00:05:34,335
Favorite
97
00:05:35,103 --> 00:05:35,871
Food
98
00:05:36,383 --> 00:05:38,943
My favorite food is pizza
99
00:05:39,199 --> 00:05:41,247
Type in your favorite food
100
00:05:42,783 --> 00:05:45,599
Console.log
101
00:05:46,879 --> 00:05:49,183
You like
102
00:05:49,951 --> 00:05:50,975
Add our placeholder
103
00:05:53,279 --> 00:05:54,047
Favorite
104
00:05:54,559 --> 00:05:55,071
Food
105
00:05:56,351 --> 00:05:57,631
You like pizza
106
00:05:58,399 --> 00:06:00,703
Maybe if I like something else like sushi
107
00:06:00,959 --> 00:06:02,239
Well you like sushi
108
00:06:03,007 --> 00:06:05,567
Another example of a string could be an email
109
00:06:05,823 --> 00:06:07,871
Let email equals
110
00:06:08,639 --> 00:06:09,919
Then type in your email
111
00:06:11,455 --> 00:06:12,735
I'm just going to make one up
112
00:06:14,015 --> 00:06:16,063
Bro at gmail.com
113
00:06:17,343 --> 00:06:19,647
Cancel that log
114
00:06:21,695 --> 00:06:24,255
Your email is
115
00:06:25,279 --> 00:06:25,791
Email
116
00:06:27,583 --> 00:06:31,935
Your email is bro at gmail.com let me make the G lowercase
117
00:06:32,703 --> 00:06:36,543
Now an important thing with strings is that strings can contain numbers
118
00:06:37,055 --> 00:06:39,103
After bro I'll add one two three
119
00:06:39,615 --> 00:06:42,175
So a string is a series of characters
120
00:06:42,431 --> 00:06:46,783
They can include numbers but we can't use these numbers for any sort of math
121
00:06:47,039 --> 00:06:52,415
Strings have a different behavior from numbers numbers we can use in arithmetic expressions
122
00:06:52,671 --> 00:06:54,207
Strings not so much
123
00:06:54,463 --> 00:06:58,815
All right let's turn these lines into comments then I will discuss boolean's
124
00:06:59,583 --> 00:07:04,703
Okay bullions are either true or false typically they're used as Flags in your program
125
00:07:06,495 --> 00:07:12,639
Online equal true Boolean or either true or false is somebody online or
126
00:07:12,895 --> 00:07:13,663
Or are they offline
127
00:07:13,919 --> 00:07:15,711
This is the other true or false
128
00:07:16,735 --> 00:07:20,063
I will display the type of my variable online
129
00:07:20,831 --> 00:07:22,879
Cancel that log type of
130
00:07:23,391 --> 00:07:24,159
Online
131
00:07:24,671 --> 00:07:27,487
So online is a Boolean variable
132
00:07:28,511 --> 00:07:31,327
Let's display our variable within a template literal
133
00:07:32,351 --> 00:07:34,143
Type in whatever your first name is
134
00:07:34,399 --> 00:07:36,703
Bro is online
135
00:07:36,959 --> 00:07:39,519
Then I will insert a placeholder
136
00:07:40,287 --> 00:07:42,847
Add my Boolean variable of online
137
00:07:43,103 --> 00:07:47,199
Bro is online that is true if I were to change this to false
138
00:07:48,223 --> 00:07:50,271
Bro is online is false
139
00:07:50,783 --> 00:07:53,855
Boolean's are typically used as a sort of flag
140
00:07:54,623 --> 00:07:56,671
So another example could be
141
00:07:56,927 --> 00:08:02,559
For sale is something for sale or not let's say that we are selling
142
00:08:03,327 --> 00:08:04,351
I don't know cars
143
00:08:05,631 --> 00:08:07,167
Is this car for sale
144
00:08:07,679 --> 00:08:09,471
I can set this to be true
145
00:08:09,727 --> 00:08:10,495
Or false
146
00:08:11,263 --> 00:08:13,823
Let's console.log
147
00:08:14,079 --> 00:08:17,151
Is this car for sale
148
00:08:18,943 --> 00:08:21,247
Boolean variable
149
00:08:21,503 --> 00:08:22,015
For sale
150
00:08:23,039 --> 00:08:25,855
Is this car for sale that is true
151
00:08:26,111 --> 00:08:29,439
Another example let's say that somebody is enrolled in school
152
00:08:29,695 --> 00:08:30,975
Like in college courses
153
00:08:31,743 --> 00:08:33,023
We could say
154
00:08:33,535 --> 00:08:34,815
Is student
155
00:08:35,327 --> 00:08:37,375
Is somebody a student are they enrolled
156
00:08:37,631 --> 00:08:39,423
This can be true or false
157
00:08:40,447 --> 00:08:42,495
Cancel that log
158
00:08:44,543 --> 00:08:45,823
Enrolled
159
00:08:47,615 --> 00:08:48,895
Call Lynn space
160
00:08:49,919 --> 00:08:51,455
Is student
161
00:08:53,503 --> 00:08:56,319
Is the student enrolled in classes that is true
162
00:08:56,575 --> 00:08:59,903
They're either true or false
163
00:09:00,159 --> 00:09:03,231
Typically we don't use them as direct output like you see here
164
00:09:03,487 --> 00:09:06,047
We usually use them with if statements to check something
165
00:09:06,303 --> 00:09:09,887
Like if somebody is online do this if not do something else
166
00:09:10,143 --> 00:09:11,423
Is a car for sale
167
00:09:11,679 --> 00:09:15,519
If that's true then display the car if it's not then hide it
168
00:09:15,775 --> 00:09:19,103
We'll have more practice with boolean's when we reach if statements
169
00:09:19,615 --> 00:09:23,199
All right now what we're going to do is we will close out of Dev tools
170
00:09:23,711 --> 00:09:26,015
Will display some variables within our web page
171
00:09:26,271 --> 00:09:28,575
So let's delete everything we have
172
00:09:29,855 --> 00:09:31,647
I'll create three variables
173
00:09:33,183 --> 00:09:34,463
Full name
174
00:09:34,975 --> 00:09:35,743
Equals
175
00:09:35,999 --> 00:09:37,535
Type in your full name
176
00:09:38,047 --> 00:09:41,631
Feel free to add a space between your first name and last name
177
00:09:42,399 --> 00:09:44,959
What age type in your age
178
00:09:47,007 --> 00:09:48,287
Add
179
00:09:49,567 --> 00:09:50,591
Student
180
00:09:51,103 --> 00:09:53,407
Equals if you're a student type true
181
00:09:53,919 --> 00:09:55,711
If you're not in school type false
182
00:09:56,223 --> 00:10:01,343
I am not in school anymore so I will type false we will go to our HTML file
183
00:10:02,111 --> 00:10:04,159
Then add some HTML elements
184
00:10:04,927 --> 00:10:07,231
I will add three paragraph elements
185
00:10:07,999 --> 00:10:09,279
So that's one
186
00:10:09,535 --> 00:10:11,071
Two three
187
00:10:11,583 --> 00:10:14,399
I will give my first paragraph and ID of
188
00:10:14,655 --> 00:10:15,167
P1
189
00:10:16,191 --> 00:10:19,263
Then let's do the same with the other two paragraphs
190
00:10:19,519 --> 00:10:21,567
Let's rename the second SP2
191
00:10:22,079 --> 00:10:24,127
And the third as P3
192
00:10:25,663 --> 00:10:29,759
So to change the text content of an HTML element
193
00:10:30,271 --> 00:10:31,295
We're going to type
194
00:10:31,807 --> 00:10:34,879
Document meaning the document of our web page
195
00:10:35,647 --> 00:10:37,183
Then we will get
196
00:10:37,695 --> 00:10:40,255
Are element by its ID
197
00:10:40,767 --> 00:10:42,815
Get element by ID
198
00:10:43,583 --> 00:10:46,911
Then within a set of parentheses within a set of quotes
199
00:10:47,167 --> 00:10:49,471
We will select the ID that we need
200
00:10:49,727 --> 00:10:51,007
Let's start with P1
201
00:10:51,775 --> 00:10:56,127
Then add dot text content to change the text content
202
00:10:57,151 --> 00:10:59,199
Then we will set the sequel to
203
00:10:59,455 --> 00:11:01,759
A variable or a template literal
204
00:11:02,271 --> 00:11:06,367
Let's begin with a variable so full name
205
00:11:08,159 --> 00:11:10,719
Are P1 elements should display your full name
206
00:11:11,487 --> 00:11:13,279
Let's do this with P2
207
00:11:15,071 --> 00:11:16,607
I'm going to zoom out a little bit
208
00:11:17,631 --> 00:11:21,215
P2 dot text content equals age
209
00:11:21,471 --> 00:11:23,007
It says that I'm 25
210
00:11:24,287 --> 00:11:25,567
And then P3
211
00:11:26,335 --> 00:11:28,639
Let's display students or better yet
212
00:11:29,151 --> 00:11:30,687
Is student let's change that
213
00:11:31,711 --> 00:11:32,991
Is student
214
00:11:33,247 --> 00:11:37,343
False I am not a student but you might be though that might be true
215
00:11:37,599 --> 00:11:42,463
Then let's display our variables along with some text using a template literal
216
00:11:43,487 --> 00:11:45,023
Let's copy our full name
217
00:11:46,815 --> 00:11:51,935
Your name is at a placeholder place our variable name
218
00:11:52,703 --> 00:11:54,239
Your name is bro code
219
00:11:54,495 --> 00:11:55,519
Or whatever your name is
220
00:11:57,311 --> 00:11:58,847
Let's cut our age variable
221
00:11:59,871 --> 00:12:01,151
You are
222
00:12:02,175 --> 00:12:03,455
Variable age
223
00:12:03,967 --> 00:12:05,247
Years old
224
00:12:05,503 --> 00:12:07,039
You are 25 years old
225
00:12:08,319 --> 00:12:10,367
And then let's cut his student
226
00:12:11,135 --> 00:12:12,927
Add a template literal
227
00:12:13,951 --> 00:12:15,231
Let's say
228
00:12:15,487 --> 00:12:18,047
Enrolled are you enrolled in school
229
00:12:19,327 --> 00:12:20,607
Add a placeholder
230
00:12:20,863 --> 00:12:22,143
Play Star variable
231
00:12:22,911 --> 00:12:23,679
Enrolled
232
00:12:23,935 --> 00:12:26,239
That is false I am not in school anymore
233
00:12:26,495 --> 00:12:32,639
All right everybody so those are variables it's a container that stores a value the variable behaves as if it were
234
00:12:32,895 --> 00:12:38,271
What's the value it contains there's a couple different basic data types you have strings which is a series of texts
235
00:12:38,527 --> 00:12:40,319
Numbers and boolean's
236
00:12:40,575 --> 00:12:46,463
There's more advanced data types but will cover that later and well those are variables in JavaScript
16921
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.